You can do this using grep
's -f
option (that's lower-case -f
, not -F
):
% echo -e 'Dog\nFish\nCat\nShoes' > ./file1.txt
% echo -e '1,shoes,red\n2,apple,black\n3,fog,blue' > ./file2.csv
# Grab all lines from the CSV that match a pattern from file1:
% grep -if ./file1.txt ./file2.csv
1,shoes,red
# Grab all lines from the CSV that DON'T match a pattern from file1:
% grep -vif ./file1.txt ./file2.csv
2,apple,black
3,fog,blue
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, but sed
interprets each line of the file as a command rather than a simple pattern like grep
does.