Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Overview of Grep and Regular Expression

Similar presentations


Presentation on theme: "An Overview of Grep and Regular Expression"— Presentation transcript:

1 An Overview of Grep and Regular Expression
By: Shuwei Chen

2 What is Grep? Text search utility Written for Unix
Global Regular Expression Print

3 Grep Format grep options pattern inputFileNames
grep -i apple fruitlist.txt

4 Basic Grep Usage Text file fruitlist.txt grep apple fruitlist.txt
banana pineapple Apples grep apple fruitlist.txt Did not return Apples, case sensitive.

5 Common Grep Options -i -v -w -x Ignores case distinctions
Lines that do NOT contain pattern -w Searches for pattern as a word -x Said pattern must match entire line

6 Common RegEx “.” – Any single character “?” - Zero or one times
p.g -> pig, pog, pag, peg “?” - Zero or one times las?t -> last, lat “*” – Zero or more times las*t -> last, lat, lasst, lassst “+” – One or more times las+t -> last, lasst, lassst

7 Common RegEx Cont. “{n}” – Exactly n times “{n,}” – n or more times
a{5} -> aaaaa “{n,}” – n or more times a{2} -> aa, aaa, aaaa “{,m}” – At most m times a{,3} -> a, aa, aaa “{n,m}” – n to m times a{2, 3} -> aa, aaa

8 Common Regex Cont. “[a,b,c]” – Any single character in bracket
b[o,b,q,w,e] -> bo, bb, bq, bw, be “[a-z]” – Dash is a range indicator b[a-d] -> ba, bb, bc, bd “[^a,b,c]” - Any single character not in bracket b[^a-y] -> bz

9 Other RegEx “[:digit:]” – Any digits
“[:alpha:]” – Any alphabetic characters “[:upper:]” – Any uppercase characters “[:lower:]” – Any lowercase characters “^” – At the beginning of the line “$” – At the end of the line Other more complicated RegEx patterns

10 Sources http://www.gnu.org/software/grep/manual/grep.pdf


Download ppt "An Overview of Grep and Regular Expression"

Similar presentations


Ads by Google