Presentation is loading. Please wait.

Presentation is loading. Please wait.

Grep Allows you to filter text based upon several different regular expression variants Basic Extended Perl.

Similar presentations


Presentation on theme: "Grep Allows you to filter text based upon several different regular expression variants Basic Extended Perl."— Presentation transcript:

1 grep Allows you to filter text based upon several different regular expression variants Basic Extended Perl

2 Grep syntax Grep [args] 'pattern' file1 file2 …
Filters out the lines containing a match to the pattern Ex: grep James file.csv

3 Grep: common arguments
-P perl regular expression -v inverse filter -i ignore case -r recurse through directories -c count the matches -l files with matches -E extended grep, same as egrep

4 Grep Examples grep “hello world” < inputfile
egrep '[0-1]?[0-9]:[0-1]?[0-9]:[0-5]?[0-9]' inputfile grep -lr “08/09/2016” logDir grep -ic “error” logfile egrep -v '2015|2014' logfile grep rhasting /etc/passwd

5 Sed syntax Almost always used in the form of
Sed 's/pattern/replacement/' <filename> The character after the “s” is the delimiter, usually a '/' slash. When pumping pathnames, you may want to change the delimiter to something else to prevent the following sed 's/\/usr\/bin\/perl/\/usr\/local\/bin\/perl/' <input Better to use sed 's:/usr/bin/perl:/usr/local/bin/perl:' <input

6 Find – How to find a file Find a file based on name, path, date created or accessed, across devices on on this filesystem only, and much more. find /home -iname '*.pl' find /home -iregex '.*rich.*\.pl' find /home -ctime +30

7 AWK An excellent filter and report writer. Many UNIX utilities generates rows and columns of information. AWK is an excellent tool for processing these rows and columns, and is easier to use AWK than most conventional programming languages. PERL was originally designed to replace AWK.

8 AWK syntax Sample program BEGIN { print "START" } { print }
END { print "STOP" }

9 AWK syntax cont #!/bin/awk -f { If ($1 == "#START") { FS=":";
} else if ($1 == "#STOP") { FS=" "; } else { #print the Roman number in column 3 print $3 }

10 PERL Practical Extraction and Reporting Language
One of the earliest robust RegEx implementations. Matches literal characters or strings Special characters Non-printable characters \t \v Character classes [] Negated character classes [^] Repeating characters ?* {}

11 PERL cont Character class subtraction [a-z-[aieou]]
Shorthand character classes \d \s \w \a DOT '.' matches anything Anchors: ^ and $ Word Boundary \b Alternation [Cat|Dog] Repetition: + * {} Grouping () /major(ity)/ Backreferences <([A-Z][A-Z0-9]*)\b[^>]*>.*?</\1>

12 PERL Cont Lookahead (?!expr) and (?=expr)
Lookbehind (?<!expr) and (?<=expr)

13 Did we make it this far! Inconceivable!


Download ppt "Grep Allows you to filter text based upon several different regular expression variants Basic Extended Perl."

Similar presentations


Ads by Google