I have a file containing words (one per line) such as
Dog
Fish
Cat
Shoes
I have a secondary file in CSV format such as
1,shoes,red
2,apple,black
3,fog,blue
I would like to use grep with the first file being the search pattern, if a line in the secondary file contains a word in the first file I would like to entirely remove the line in the secondary file.
I am not sure grep is even the way to go about this.
EDIT:
bash scripting
Best Answer
You can do this using
grep
's-f
option (that's lower-case-f
, not-F
):Detailed explanation:
grep
— self-explanatory-v
— means 'return lines not matching the input pattern'-i
— means 'use case-insensitive matching' (since your first file had capital letters and the CSV didn't)-f
— means 'interpret each line in the specified file (file1.txt
) as a pattern to use for matching'Depending on the results you want and the contents of your files, you may also want to read into the
-F
and-w
options.If you need to edit the file in-place, i think you can do this with
sed
's-f
option, butsed
interprets each line of the file as a command rather than a simple pattern likegrep
does.