| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
grep and egrep Regular Expressions
Grep and egrep are Unix and Linux utilities
which filter an incoming file, outputting all lines which match a regular expression and not outputting lines
that fail to match. The original grep uses a somewhat restricted regular expression set, and egrep (in full, the
extended global regular expression processor) has somewhat further facilities. Fgrep (the f stands for fake)
doesn't use regular expressions at all - it checks for literal strings.
Example: grep cat demo.txtoutputs all lines from the file demo.txt that include "cat" Special characters in regular expressions such as [ ] ? and * also have a special significance to the Unix or Linux shell, and it's usual to write your regular expression in quotes to protect it from the shell.
Additionally, some versions of egrep (especially linux) support numerous extra sequences such as POSIX character groups (e.g. [[:alnum:]] for an alphanumeric character) and extended counts (e.g. {4,8} for bewteen 4 and 8 of the previous element). Take care when using these extras if you want your scripts to be portable. grep, egrep and fgrep all take a number of options to allow you further control over your matching and output. The options don't differ between egrep, fgrep and grep but there are more options available under linux than there are under Unix. The following table includes the more common options under both operating systems.
The -r option (not available on all versions of grep) allows the recursive searching of all files in subdirectories. Back to Regular Expression Home Page Jump to Elements of a regular expression Order a Regular Expression Mousemat for £4.95 inclusive |
| ||||||||||||||||||||||||||||||||||||||||||||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |