Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a CSV file with 4 columns: Itemname,Value,Description and component which is quite huge.

I have to generate a template from the above CSV file that displays only the rows of the specified component(say component='abc' which is the search criterion)

share|improve this question
    
Unless you edit your question to make it relevant to *nix, this will probably moved to Stack Overflow and/or closed. –  Anthon Jun 24 '13 at 4:30
    
@Anthon how is this not relevant to *nix? As Ignacio's answer shows, awk is perfect for this. –  terdon Jun 24 '13 at 14:23
1  
@tendon I don't see why awk is perfect for this. How does awk e.g. determine the separating character used in the CSV?. This doesn't have to be the comma, something that e.g. Ignacio assumes). This now seems more a generic programming question that belongs on Stack Overflow (if not already answered there), which is why I warned the OP. –  Anthon Jun 24 '13 at 15:18

1 Answer 1

Assuming there are no embedded commas, awk is perfect for this.

awk -F , '$4 == "abc" { print }' input.csv
share|improve this answer
1  
'print' is the default action, so you may just omit it. –  gelraen Jun 24 '13 at 11:03
1  
the separating character for CSV is not always a comma, e.g. not with the defaults for some versions of Excel. –  Anthon Jun 24 '13 at 16:36
    
Replacing the comma with something else is very, very easy. –  Ignacio Vazquez-Abrams Jun 24 '13 at 20:22

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.