[wplug] Text searching
Tom Moertel
tom at moertel.com
Fri Mar 21 19:59:06 EST 2003
On Mon, 2003-03-17 at 09:07, Doug Green wrote:
> Hi all-
>
> I have some large text files that I need to search. [...]
> Essentially, the format
> looks like this (obviously, the content is different):
>
> 1 atacaatagg atacaatagg atacaatagg atacaatagg atacaatagg atacaatagg
> 61 atacaatagg atacaatagg atacaatagg atacaatagg atacaatagg atacaatagg
>
> I need to be able to search within this kind of text file for a string of
> letters that is maybe 30-40 letters long, ignoring the spaces and numbers.
(Sorry I didn't respond to your query earlier. I saw your email only
just now.)
The following Perl one-liner will do what you need:
perl -nle 'tr/a-z//cd; print "$ARGV:$." if /PATTERN/' FILES...
Just replace PATTERN with the string you want to find and FILES with the
list of files you want to search. The output will indicate matches by
filename and line number:
file1:39
file1:993
file2:23
If you want a full explanation of the techniques used in this one-liner,
read the perlrun man page for explanations of the -n, -l, and -e
switches; the perlvar manpage for the $ARGV and $. variables; and the
perlop manpage for the tr// and // "regex quote-like" operators.
Cheers,
Tom Moertel
Moertel Consulting / www.moertel.com
More information about the wplug
mailing list