next up previous contents
Next: Regular Expressions Up: Other useful UNIX Previous: Displaying the Online

Text Search

UNIX provides a text search command called grep. It searches text for regular expressions. The simplest regular expressions are simply strings of characters. Grep will print out all lines containing the search expression, unless told otherwise:

$cat d
This will be the content of
our new file!
$grep our d
out new file!

We can specify multiple files on the command line:

$cat e
This will be the content of
our old file!
$grep our d e
d:our new file!
e:our old file!

Or we can count the number of occurrences:

$grep -c our d e

Mark O. Stitson
Wed Sep 25 10:45:32 BST 1996