The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 04-21-2009
fwellers fwellers is offline
Registered User
  
 

Join Date: Mar 2008
Location: Northern, VA
Posts: 23
That's pretty cool. thanks. It doesn't fully solve for me though.
I should have mentioned I have to add some to it, and add commas.
So I can use the tr command to go to newfile, then:
cat newfile|awk '{printf("mydata,moredata,%s,%s,%s\n",$1,$2,$3) }'

but, even that is not a full solution yet, because how will the script know how many fields are in the file, and be able to decide how many elements to put on the right side of the printf statement ?

For eg, if the file had 10 columns that the tr command turned into one line with 10 fields, how will I create a print statement that will know there were 10 fields so I can use them ?

Thanks,
floyd