Re: Strip trailing commas
Posted in 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}}' > Try...... cat file.dat | nawk -v LINE=$ for ( i=1;i<=(NF-1);i++) {printf "%d," $i}}' printf "%d",$NF This will print all but the last with a comma. > 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? > > -----== Posted via Deja News, The Leader in Internet Discussion ==----- > http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum -- Vic Goldberg Manager, DBA Team, Acting Manager, Technical Integration Cornell University (607) 254-7441 (Voice) (607) 255-6982 (Fax)