5.2 Grep and tr filters

4. Commands to learn:
Filters:
grep, egrep, fgrep (1)  - search a file for a string or regular expression
tr (1)			- translate characters

5. Grep searches for regular expressions on one or more files. Where there 
is a match, grep outputs the [file name and] line that matches.  Grep can 
also output lines which do not match since it knows about both.   fgrep is 
a fast grep which searches using fixed strings (no regular expressions) 
while egrep is an extended grep that uses additional special characters 
(e.g. | for or of 2 or more regular expressions.)

On the HP-UX and other Posix implementations, egrep and fgrep have been 
replaced by grep -E and grep -F respectively. Look at the man page for 
grep for more details.

Examples :

$ ls /bin | grep '^[a-z][a-z]$'

$ ls | grep '^d'

$ ls | grep -v '^d'

$ ls /bin | grep -c '^[a-z][a-z]$'

$ tr '[a-z]' '[A-Z]' < oldfile > newfile

$ tr -cs '[A-Z][a-z]' '[\012*]' # replace with ascii newline character any 
				non-letter or space characters

$ tr -s ' ' ' '		# squeeze out extra space characters

Questions? Robert Katz: rkatz@ned.highline.edu
Last Update July 23, 2002