Can anyone help with a script (probably awk printf related) that will take my delimited file, remove some unwated fields and add some additional fields throught the file:

eg

1,4,fd,4r54,3,,4454

if i wanted to keep fields 1,2,4,7 and add in two empty fields between fields 4 and 7 so the output would look like

1,4,4r54,,,4454

Is this possible?

M

link|improve this question

75% accept rate
feedback

2 Answers

up vote 1 down vote accepted

You can do that with:

awk -F , '{ printf "%s,%s,%s,,,%s\n" , $1 , $2 , $4 , $7 }' file
link|improve this answer
Perfect thanks!!! – mattm123 Oct 29 '10 at 11:37
feedback

If you already have the delimited file, than this should be very easy. At the top, it should list all of the fields, just take out the ones you do not want, and insert the ones you do want. I warn you though, with will effect all of the entries that are currently in the file. I would use a program like Excel or open offices version of Excel to do this with a file that currently has entries.

If you need anymore help, please comment, I will try to help as much as possible.

Good Luck-

link|improve this answer
oh no i need to perform this in shell scrip, no excel for me unfortunatly – mattm123 Oct 28 '10 at 15:30
Sorry, I saw Unix and didn't know if you used WINE, or if you were just going to use VI. – David Oct 28 '10 at 17:26
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.