Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pattern Matching CSCI N321 – System and Network Administration.

Similar presentations


Presentation on theme: "Pattern Matching CSCI N321 – System and Network Administration."— Presentation transcript:

1 Pattern Matching CSCI N321 – System and Network Administration

2 Section Overview Regular Expressions Matching Characters Grouping/Repetition Characters Tagging (Buffering) Character Classes

3 References CQU 85321 System Administration Course Textbook  Chapter 7 Chapter 7 Lectures  1999 #7 1999 #7

4 Pattern Matching Powerful tool to extract/modify file data Regular Expressions Special “string” used to match patterns Special (Meta) Characters  Matching  Grouping/Repeating  Tagging (buffering) Use with ASCII files

5 Programs supporting REs Extracting information grep egrep Modifying information sed & awk ex & vi Filename globbing versus REs

6 Matching Characters CharacterMatches cAny 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

7 Grouping/Repetition Characters CharacterMatches *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

8 Tagging (Buffering) Takes the output from one RE and uses it again later REs to reuse are in \( \) - Tagging Buffers 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.

9 RE Character Classes LiteralMatches [: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

10 RE Character Classes (Con’t) LiteralMatches [: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])


Download ppt "Pattern Matching CSCI N321 – System and Network Administration."

Similar presentations


Ads by Google