Introduction to Regular Expression for sed & awk by Susan Lukose.

4
Introduction to Regular Expression for sed & awk by Susan Lukose

Transcript of Introduction to Regular Expression for sed & awk by Susan Lukose.

Page 1: Introduction to Regular Expression for sed & awk by Susan Lukose.

Introduction to Regular Expression for sed & awk

bySusan Lukose

Page 2: Introduction to Regular Expression for sed & awk by Susan Lukose.

Regular Expression• Regular Expression way to match text with patterns

Regular Expression Example of Matched Text

Example of Unmatched Text

abc abcdefgcccdabcgf

bcagjjfggjkgfkk

^abc abcjjdje dgabcjjjd

abc$ jhsjdabcabc

abcchghhsd

a.b acbdavb

avhsjvhbab

a.*b abajjdjkxb

ba

a*b bhsghghaaaaaabmnjkk

acb

a.+b acbahjhhjjbcsdfs

ab

a+b aaaaaab bkfjdkj

Page 3: Introduction to Regular Expression for sed & awk by Susan Lukose.

Regular Expression

• {n} Match exactly n times{n,} Match at least n times{n,m} Match at least n but not more than m times

regular expression example of matched text example of unmatched text

a?b bcabd

aab

Page 4: Introduction to Regular Expression for sed & awk by Susan Lukose.

Regular Expression• Grouping could be done with ()

– (ab)– gg(ab)*gg

• Class could be specified []– [abc] Match any of a, b, and c. – [a-z] Match any character between a and z. (ASCII order) – [^abc] A caret ^ at the beginning indicates "not". In this case, match anything other than a, b, or c.

• regular expression should be specified between //• Special characters like ^, $, . etc.. Could be matched by escaping with \