Upload
kovit
View
22
Download
2
Embed Size (px)
DESCRIPTION
Pattern Matching. CSCI N321 – System and Network Administration. Section Overview. Regular Expressions Matching Characters Grouping/Repetition Characters Tagging (Buffering) Character Classes. CQU 85321 System Administration Course. References. Textbook Chapter 7. Lectures 1999 #7. - PowerPoint PPT Presentation
Citation preview
Pattern Matching
CSCI N321 – System and Network Administration
Section Overview
Regular Expressions
Matching Characters
Grouping/Repetition Characters
Tagging (Buffering)
Character Classes
References
CQU 85321 System Administration Course
TextbookChapter 7
Lectures1999 #7
Pattern Matching
Powerful tool to extract/modify file dataRegular Expressions Special “string” used to match patterns Special (Meta) Characters
Matching Grouping/Repeating Tagging (buffering)
Use with ASCII files
Programs supporting REs
Extracting information grep egrep
Modifying information sed & awk ex & vi
Filename globbing versus REs
Matching CharactersCharacterCharacter MatchesMatches
c Any single character (other than a RE special character)
\Removes the special meaning from s RE special character (escape)
. Matches any single character
^ Matched start of line
$ Matches end of line
[chars] Matches any one character in chars
[^chars] Matches any one character not in chars
Grouping/Repetition Characters
CharacterCharacter MatchesMatches
* 0 or more of previous RE
+ 1 or more of previous RE
? 0 or 1 occurrence of previous RE
\{n\} Exactly n occurrences of previous RE
\{n,\} At least n occurrences of previous RE
\{n,m\} between n & m occurrences of previous RE
| One of two different REs (alternation)
( ) Groups a collection of REs
Tagging (Buffering)
Takes the output from one RE and uses it again laterREs to reuse are in \( \) - TaggingBuffers are referenced by \n where n is the register number
$ egrep ‘([a-z])([a-z])\2\1’ /usr/share/dict/words
Would return words like attach, better, and common.
RE Character Classes
LiteralLiteral MatchesMatches
[:alnum:] Any alphabetical or numeric character
[:cntrl:] Any control character
[:lower:] Any lowercase letter
[:space:]Space, form-feed, newline, carriage return, horizontal tab, vertical tab
[:alpha:] Any alphabetical character
[:digit:] Any numeric character
RE Character Classes (Con’t)
LiteralLiteral MatchesMatches
[:print:] Any printable character
[:upper:] Any uppercase character
[:blank:] Blank, usually space and tab
[:graph:] Any printable character except space
[:punct:]Any printable character which is not a space or an alphanumeric character
[:xdigit:] any hexadecimal digit ([0-9a-eA-E])