Unit - IV
Unit - IV
Filters
Contents
The Grep Family
Other Filters
The stream editor sed
The awk pattern scanning and processing
language
Good Files and Good Filters
The Grep Family
• searches the named pipes or the standard input and prints each
line that contains an instance of the pattern
• Patterns are a slightly restricted form of the string specifiers called regular
expressions
• The option –n prints line numbers,-v inverts the sense of the test and –y
makes lower case letters in the pattern match letters of either case in the file
• The meta characters ^ and $ anchor the pattern to the beginning(^) and
end($) of the line.
• For example prints lines that begin with from, which are more
likely to be message header lines.
• grep supports character classes. so [a-z] matches any lower case letter.[^0-9]
matches any non-digit.
• A period ‘.’ matches any character.
• The closure operator ‘*’ matches applies to the previous character or metacharacters
in the expression, and collectively they match any number of successive matches of
the character or metacharacter.
– For example x* matches a sequence of x’s as long as possible
– [a-zA-Z]* matches an alphabetic string
– .* matches anything up to a newline
– .*x matches anything upto and including the last x on the line
• Closure applies to only one character
• No grep expression matches a newlne
• This command searches for users without passwords
• fgrep searches for many string literals simultaneously
• egrep interprets true regular expression but with an
or operator and parenthesis to group expressions
• Both egrep and fgrep accept a –f option to specify a
file from which to read the pattern
• There are two other closure operators in egrep- +
and ?.
– The pattern x+ matches one or more x’s
– The pattern x? Matches zero or one x
• egrep is excellent at word games that involves searching the
directory for words with special properties
– To find all words of six or more letters that have the letters in alphabetical
order
• Sort
• The idea in awk is much the same as in sed,but the details are based more
on the C programming language than on a text editor
• Usage is just like sed
• END actions are performed after the last line of input has been
processed