> I would like to concatenate every 3 lines from a file > to 1 line in a new file.
while read line1 do read line2 read line3 done exit 0
Also, if you know you are going to use a posix shell, try using read -r instead of read by itself. Otherwise, the shell will silently eat backslashes.
chris
> > I would like to concatenate every 3 lines from a file > > to 1 line in a new file. > > sed 'N;N;s/\n//g' oldfile > newfile
If the number of lines in "oldfile" is two more than a multiple of three, then you will discover that the way that sed handles "end-of-file hit while trying to execute the N command" can be annoying. To work around it use: sed 'N;$! N;s/\n//g' oldfile > newfile
Ken Pizzini
>Somebody please explain why we can't use xargs:
>$ jot 10 | xargs -n 3 >1 2 3 >4 5 6 >7 8 9 >10
Because it won't work if the input contains any space, tab, backslash, single-quote or double-quote characters.
Geoff Clare
Interesting idea, but it does not work, e.g.:
$ echo 1 2 3 4 5 6 '7 8' | xargs -n 3 1 2 3 4 5 6 7 8
"xargs" handles (white space separated) tokens, not lines. "xargs -l3" is a bit better, but still no cigar.
$ /bin/echo "1 2\n 3 4 5 6 7 8" | xargs -l3 1 2 3 4 5 6 7 8
Heiner Marxen
documented on: 1999.09.29 Wed 19:04:20