1

I would like to write a script (probably AWK printf related) that will take my delimited file, remove some unwanted fields and add some additional fields througout the file:

For example:

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

I want 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?

2 Answers 2

1

You can do that with:

awk -F , '{ printf "%s,%s,%s,,,%s\n" , $1 , $2 , $4 , $7 }' file
0
0

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-

2
  • oh no i need to perform this in shell scrip, no excel for me unfortunatly
    – mattm123
    Oct 28, 2010 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, 2010 at 17:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .