Shell Programming/Regular expressions

Regular expressions are used generally to manipulate strings by external programs like  and.

Commonly used characters in regular expression
^ Anchor to beginning of line $ Anchor to end of line . Any single character [ ] Encloses pattern matching characters

Matching Characters
[:alnum:] Alphanumeric characters [:alpha:] Letters [:ascii:] ASCII characters [:blank:] Space or tab [:cntrl:] ASCII control characters [:digit:] Digits [:graph:] Noncontrol, nonspace characters [:lower:] Lowercase letters [:print:] Printable characters [:punct:] Punctuation characters [:space:] Whitespace characters, including vertical tab [:upper:] Uppercase letters [:xdigit:] Hexadecimal digits

Extended grep mode
The -E mode may be used in grep with the following characters preceded by '\'.

? Match is optional but may be matched at most once "*" Must be matched zero or more times (without "") + Must be matched one or more times {n} Must be matched n times {n, } Must be matched n or more times {n,m} Must be matched between n and m times

Examples of regular expression in use

 * Look for text in file, example_text_file, ending with 'e':

Crazy Monkey Crazy Donkey Cranky Money in another_text_file:
 * Look for:

The above command tells grep to use extended mode, find "Cra", followed by any number of string, followed by space, followed by printable character, followed by "o", followed by three characters, and search this in another_text_file.