Naman
Naman

Reputation: 2669

Shell, grep for list of patterns

I have two csv files a.csv and b.csv. I 'cut' one column from the a.csv file and now I want to grep for each one of the string from this column in second file b.csv. Can someone please help me in writing a shell script for this?

Upvotes: 0

Views: 322

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 80931

You want the -f (and likely -F and possibly -w) flags to grep for this sort of task.

$ cut ... a.csv > tmp
$ grep -Ff tmp b.csv

You can do this without the temporary file on shells that support process substitution.

$ grep -Ff <(cut ... a.csv) b.csv

Upvotes: 1

Related Questions