| [etc] Regular Expression Tools |
| HOME |
[Date Prev][Date Next][Date Index]
[etc] Regular Expression Tools
1. Egrep:
The egrep tool can be used to search for tools through a specific file or a
set of Files..
For example:
I used the following command to search for lines begining with "From: " or
"Subject: " in a mailbox file.
NOTE: The '^' and '|' characters are special characters for forming regular
expressions. You can get more information on this by going to
http://www.comp.leeds.ac.uk/Perl/matching.html
%egrep '^(From|Subject): ' mbox
And i got the following output
From: Alan Verlo <darkman@evl.uic.edu>
Subject: Re: Password authentication fail..
From: Shashank R Khanvilkar <skhanv1@uic.edu>
Subject: Test mail from Icarus
Subject: [ProblemDB] 159966: How to change shell on Icarus.
From: consult@uic.edu
From: Alan Verlo <darkman@evl.uic.edu>
Subject: Re: Password authentication fail..
From: "Barnes & Noble.com" <BNcom@email.bn.com>
Subject: Free Shipping on New and Used Textbooks
Subject: Re: [ProblemDB] 159966: How to change shell on Icarus.
From: consult@uic.edu
From: Mani Ramadas <mramadas@cs.ohiou.edu>
Subject: Re: tcptrace examples
From: "Shashank Khanvilkar" <shashank@evl.uic.edu>
Subject: An Attachement example
Subject: SourceForge Account Registration
From: noreply@sourceforge.net
From: Fred Baker <fred@cisco.com>
Subject: Re: [Diffserv] RFC 3289 DiffServ MIB discrepancies
From: "Rubin Chheda." <rchhed1@uic.edu>
Subject: ROOMMATE NEEDED
but the following command searches through all the files, but only lists the
files which has the required lines..
%egrep '^(From|Subject): ' *
egrep: lib: Is a directory
mbox:From: Alan Verlo <darkman@evl.uic.edu>
mbox:Subject: Re: Password authentication fail..
mbox:From: Shashank R Khanvilkar <skhanv1@uic.edu>
mbox:Subject: Test mail from Icarus
mbox:Subject: [ProblemDB] 159966: How to change shell on Icarus.
mbox:From: consult@uic.edu
mbox:From: Alan Verlo <darkman@evl.uic.edu>
mbox:Subject: Re: Password authentication fail..
mbox:From: "Barnes & Noble.com" <BNcom@email.bn.com>
mbox:Subject: Free Shipping on New and Used Textbooks
mbox:Subject: Re: [ProblemDB] 159966: How to change shell on Icarus.
mbox:From: consult@uic.edu
mbox:From: Mani Ramadas <mramadas@cs.ohiou.edu>
mbox:Subject: Re: tcptrace examples
mbox:From: "Shashank Khanvilkar" <shashank@evl.uic.edu>
mbox:Subject: An Attachement example
mbox:Subject: SourceForge Account Registration
mbox:From: noreply@sourceforge.net
mbox:From: Fred Baker <fred@cisco.com>
mbox:Subject: Re: [Diffserv] RFC 3289 DiffServ MIB discrepancies
mbox:From: "Rubin Chheda." <rchhed1@uic.edu>
mbox:Subject: ROOMMATE NEEDED
*******************************************************
For building regular expressions the square brakets [..] can be very
useful..
for e.g.
"<H[123456]>" , which matches <H1> , <H2> , <H3> , etc. This can be useful
when searching for HTML headers.
for e.g using the folliwing cpmmand in the ~shashank/public_html directory
gave me the following results
Command: %egrep '<H[123456]>' *
Result:
test1.html: <H1>Shashank Khanvilkar</H1>
test1.html.save: <H1>Shashank Khanvilkar</H1>
Note: Sunstituting the above command with
%egrep '<H[1-6]>' *
leads to the same result.
the '-' symbolizes between,
*******************************************************