O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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)' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required