Re: Strip trailing commas
Posted in 1998
Oleg Milenkiy — — source: Informix-list mailing list archive (1991-1998)
cl3071@sbc.com wrote: > > I am trying to write a ksh function that will take values from an input file, > in a collumn or one line, and concatinate them into one line with comma > seperators. The problem is, how do I truncate the trailing comma? i.e.: > > input: 11 > 22 > 33 > > output: 11,22,33 > > so far I have > > cat file.dat | nawk -v LINE=$line 'BEGIN { FS=",";ORS=",";OFS=","} > { > for ( i=1;i<=NF;i++) > {print $i}}' > > this gives the output: > 11,22,33, > > Even if the input is already in a single line. > > How do I strip that darn last comma? The pipe sed "s/,$//" will do the job. Oleg