[Level 2] Join lines by sed commands.

If you want to join lines in shell script, you could use sed command.
#!/bin/bash
cat > /tmp/t.txt <<EOF
eth0
eth1
eth2
eth3
eth4
eth5
eth6
lo0
EOF
sed -e :a -e '$!N; s/\n/,/; ta' /tmp/t.txt
$ ./joinLinesBySed.sh
eth0,eth1,eth2,eth3,eth4,eth5,eth6,lo0
Wish this helps.
regards,
Stanley Huang

Comments

Popular posts from this blog

[Level 1] Rar tool for Solaris.

[Level 2] iif in Python