Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

merge 3 lines into one line please

Status
Not open for further replies.

hok1man

Technical User
Joined
Feb 16, 2008
Messages
102
hi guys,

as title so the input like this..
a, b, c
12
345
ert, test
again
again

the expected output is :
a, b, c, 12, 345
ert, test, again, again


every three lines..

thanks heaps guys
 
How about this:

Code:
cnt=1 ; while read line
do
  if [ "${cnt}" -lt 3 ] ; then
        echo "${line} \c"
        ((cnt+=1))
  else
        echo "${line}"
        cnt=1
  fi
done < /path/to/file

Regards,
Chuck
 
Thanks cspilman,

I found it
awk '{printf "%s,",$0;getline;printf "%s,",$0;getline;printf "%s,",$0}' /path/to/file
 
Or you can use sed .....
Code:
sed -e 'N;N;s/\n/, /g' file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top