Operating System - HP-UX
1752805 Members
5646 Online
108789 Solutions
New Discussion юеВ

Re: Join lines into one line

 
SOLVED
Go to solution
Hein van den Heuvel
Honored Contributor

Re: Join lines into one line

I know this horse has been beaten but here is how I would deal with the 'extra comma' problem in awk:

$ awk '{printf comma $0; comma=","}' x.txt

so we print a comma BEFORE each fresh line, but we don't want one on the first line, so we set a symbol to the value comma, after the first print.
(and again and again, but awk don't mind that :-).

fwiw,
Hein

Jose Mosquera
Honored Contributor

Re: Join lines into one line

Hi,

#AUX=`cat file.txt|tr "\n" ","`
#echo $AUX > file.aux
#cat file.aux
line1,line2,line3,line4,...,

Rgds.
Viktor Balogh
Honored Contributor

Re: Join lines into one line

Hein,

>so we print a comma BEFORE each fresh line, but we don't want one on the first line

that's exactly what I did with

# awk '!(NR-1) {printf $0} NR-1 {printf ","$0} END {print ""}'

but you solution is genious! Maybe an END section just to echo a linefeed after the last line... ;)
****
Unix operates with beer.