Search notes:

Shell: find regex's stored in a file with grep -f

grep -f regexp.txt data.csv finds lines that are stored in the data.csv that match the regular expressions that are stored in the file regexp.txt.
grep -f is the abbreviation for grep --file.

Example

The use of grep -f is demonstrated in the following simple example.
This is data.csv, the file in which we want to search for regular expressions:
abc;42;foo
def ghi;999;bar
jkl;18;baz
barbarossa;33;qux
Github repository shell-commands, path: /grep/f-regular-expressions-in-file/data.csv
This is regexp.txt, the file that contains the regular expressions. Each regular expression occupies one line:
[[:digit:]]\{3\}
ro..a
Github repository shell-commands, path: /grep/f-regular-expressions-in-file/regexp.txt
Executing grep -f regexp.txt data.csv prints the two lines that match the regular expressions stored in regexp.txt:
def ghi;999;bar
barbarossa;33;qux

See also

Shell commands

Index