Use awk to combine lines
I used this script to find to find out what version of Sendmail was on each server by package:
for i in $(cat SystemList);do ssh $i ‘hostname;pkginfo -l Sendmail | grep VERSION:;pkginfo -l OtherSendmail | grep VERSION:’ >> output;done;cat output
What ouput looks like is this:
hostname1
VERSION: 8.12.10
hostname2
VERSION: 8.13.7
hostname3
VERSION: 8.13.8
hostname4
VERSION: 8.13.8
hostname5
VERSION: 8.13.8
…
This is hard to parse, I wanted it on one line.
Per this web page: http://unix-simple.blogspot.com/2006/12/awk-script-to-combine-lines-in-file.html
I modified the code slightly and ran this:
cat output | awk ‘{d=d”"$o}
/VERSION/ {
print d
d=”"
}’
and got this:
hostname1 VERSION: 8.12.10
hostname2 VERSION: 8.13.7
hostname3 VERSION: 8.13.8
hostname4 VERSION: 8.13.8
hostname5 VERSION: 8.13.8
…
VERY cool, and easy to parse, and even to stick into Excel. ![]()
____
Make it comma delimited:
for i in $(cat SystemList);do ssh $i ‘uname -n;echo ,;crontab -l|grep -i SEARCHTEXT1;echo ,;crontab -l|grep -i SEARCHTEXT2;echo done’>>output;done;less output
cat output | awk ‘{d=d”"$o}
/done/ {
print d
d=”"
}’
