Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You can do that with:

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

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-

share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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