How can I combine odd and even numbered lines?
here it is, with sed:
sed '$!N;s/\n/,/'
and with awk:
awk '{if (e) {print p","$0;} else {p=$0;} e=!e;}'
or
awk 'NR%2==0 {print p","$0;} NR%2 {p=$0;}'
This is what the paste
command is for. Assume your output is generated with command
, then you can do:
$ command | paste -d, - -
or if the output is stored in a file
$ paste -d, - - <file.csv
Example:
paste -d, - - <<END
Line one,csv,csv,csv
Line two,csv,csv
Line three,csv,csv,csv,csv
Line four,csv
END
outputs:
Line one,csv,csv,csv,Line two,csv,csv
Line three,csv,csv,csv,csv,Line four,csv
And another one:
awk -F, ORS=NR%2\?FS:RS infile
You don't need to quote the ? with most shells.