Let's say we have a text file of forbidden lines
forbidden.txt. What is a short way to filter all lines of a command output that exist in the text file?
cat input.txt | exclude-forbidden-lines forbidden.txt | sort
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
grep like this:
$ grep -v -x -F -f forbidden.txt input.txt
That long list of options to
-vInvert the sense of the match, i.e. look for lines not matching.
-xWhen matching a pattern, require that the pattern matches the whole line, i.e. not just anywhere on the line.
-FWhen matching a pattern, treat it as a fixed string, i.e. not as a regular expression.
-fRead patterns from the given file (
Then pipe that to
sort or whatever you want to do with it.