0

Untill now I used everytime to filter, grep command

[root@host tests]# cat e
1
2
3
4
5
[root@host tests]# cat e | grep -Ev '2|3' > filtered.txt

[root@host tests]# cat filtered.txt
1
4
5
[root@host tests]#

But right now I have a large file that needs to be filtered with hundred of strings from another file. How can I do it?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

3

Sounds like you could just use grep with the following option

   -f FILE, --file=FILE
          Obtain patterns from FILE, one per line.  If this option is used multiple times or is combined with the -e (--regexp) option, search for all patterns given.  The empty file contains zero patterns, and therefore matches
          nothing.

You will also want to use both -F (use patterns as plain strings in the comparisons, not regular as expressions) and -x (compare complete lines, not substrings). If not -x, then -w (compare only whole words).

Kusalananda
  • 333,661