1

This question already has an answer here:

I have quite a large csv file (call it file.csv). It looks like this one:

col1,col2,col3,...
1,2,3
1,2,5
...

So after doing something like this cat file.csv | grep "_some_pattern_" I receive only the output values. Is there a way to append the header (the first line) to the output?

It would be very convenient...

marked as duplicate by don_crissti, HalosGhost, Jeff Schaller, Satō Katsura, Wildcard Oct 31 '16 at 20:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

you can use head to print the first line and tail to search with grep starting after the header for the pattern.

head -n 1 file.csv && tail -n +2 file.csv | grep "some pattern"

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