Saturday, April 12, 2008
Combine every 3 lines as one - Awk
$ cat details.txt
AA XX
ID23145
Singapore,1982
BB YZY
SD1243
Delhi(India),1980
DD AS
ASD324
Dubai,1981
Purpose:
-------
Combine every 3 lines as one i.e.
Required Output
----------------
AA XX,ID23145,Singapore,1982
BB YZY,SD1243,Delhi(India),1980
DD AS,ASD324,Dubai,1981
If line number is divisible by 3 then put a new line(\n) else put a comma(,) i.e.
$ awk '{printf("%s%s", $0, (NR%3 ? "," : "\n"))}' details.txt
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
2 comments:
paste -d"," - - - details.txt
perl -ple '$_ .= <>.<>; y/\n/,/'
awk '{ORS = NR%3 ? "," : "\n"}1'
sed -e '$!N;$!N;y/\n/,/'
Post a Comment