User Tools

Site Tools


grep:regex_usage

This is an old revision of the document!


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

Search the file for lines ending with the letter e.

grep "e$" filename

returns:

booze
machine
bungie

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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki