If a line ends with a colon, append the next line to it using sed


The output from my runcmdonhosts.exp expect script produces output like this:

host1:
result
host2:
result
host3:
result

I want it to be like this:

host1: result
host2: result
host3: result

First, save the output to a log file using tee -a with runcmdonhosts.exp.

Then edit that log file with vi and stript out all the ^M (CRLF) that expect adds. This is unix, we only use newline characters. (This can probably be done with sed as well.)

Then use this sed command to append the line following any line that ends with a colon to that line:

cat file | sed -e :a -e '/: $/N; s/: \n/: /; ta'

11/07/2011