8.5. egrep

egrep stands for expression or extended grep depending on who you listen to. Egrep accepts the full range of regular expressions. One of the nice features of egrep is that you can store your strings in a file and pass them into egrep.Wedo this with the -f switch. If we create a file called grepstrings and then type 484 and 47 into it:

						$ pg grepstrings 
484
47
$ egrep -f grepstrings data.f
					

this would match all records with 484 or 47 in them. The -f switch really becomes useful if you want to match a lot of patterns, and typing them in on the command line becomes awkward.

If we want to search for store codes 32L or 2CC we can use the bar sign (|), which means one or the other or both (all), separated by the bar sign.

						$ egrep '(3ZL|2CC)' ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.