grep:regex_usage
This is an old revision of the document!
Table of Contents
Grep - Regex Usage
A regular expression is a compact way of describing complex patterns in text.
With grep, you can use them to search for patterns
Assuming a file exists with the following contents:
boot book booze machine boots bungie bark aardvark broken$tuff robots
Basic Regex Search
Search the file for lines ending with the letter e.
grep "e$" filename
returns:
booze machine bungie
Extended Regex Search
grep -E "boots?" filename
returns:
boot boots
NOTE: grep -E is also known as egrep.
The regexp command ? will match 1 or 0 occurrences of the previous character.
Combine Multiple Searches
grep -E "boot|boots" filename
returns:
boot boots
NOTE: The pipe | means 'or'.
grep/regex_usage.1598096540.txt.gz · Last modified: 2020/08/22 11:42 by 192.168.1.1