Home > Archive > PERL Miscellaneous > August 2007 > How to do pattern matching for multiple files in Perl
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to do pattern matching for multiple files in Perl
|
|
|
| Hi,
I am new to Perl and know ksh better. He is what I am doing with ksh
"$ cat file_list
file1.log
file2.log
$cat file_list | xargs -L 500 egrep -ci "pattern_to_search" /dev/null
| grep -v "0$" | sort -b -t ":" -k4,4 -T "/tmp" > "summary_file"
$ cat summary_file
file1.log:2
file2.log:2
$cat file_list | xargs -L 500 egrep -A3 -i "pattern_to_search" | cut -
c1-1024 > "detail_file"
$cat detail_file
file1.log: pattern_to_search 1
file1.log: pattern_to_search 2
file2.log: pattern_to_search 6
file2.log: pattern_to_search 7"
inside the ksh script, pattern.ksh
------------------------------------------------
cat file_list | xargs -L 500 egrep -ci "pattern_to_search" /dev/null |
grep -v "0$" | sort -b -t ":" -k4,4 -T "/tmp" > "summary_file"
cat file_list | xargs -L 500 egrep -A3 -i "pattern_to_search" | cut -
c1-1024 > "detail_file"
And I was told that perl is faster than ksh. If so, how can we do the
above operation using perl. I dont think using the above statement
directly inside perl script as
`cat file_list | xargs -L 500 egrep -ci "pattern_to_search" /dev/null
| grep -v "0$" | sort -b -t ":" -k4,4 -T "/tmp" > "summary_file"`
`cat file_list | xargs -L 500 egrep -A3 -i "pattern_to_search" | cut -
c1-1024 > "detail_file"`
is the right way. Any suggestions and pointers is appreciable.
Thanks in Advance,
Kimi
| |
| Ben Morrow 2007-08-28, 7:07 pm |
|
Quoth Kimi <shafa.fahad@gmail.com>:
> Hi,
>
> I am new to Perl and know ksh better. He is what I am doing with ksh
>
<snip>
> cat file_list | xargs -L 500 egrep -ci "pattern_to_search" /dev/null |
> grep -v "0$" | sort -b -t ":" -k4,4 -T "/tmp" > "summary_file"
> cat file_list | xargs -L 500 egrep -A3 -i "pattern_to_search" | cut -
> c1-1024 > "detail_file"
>
> And I was told that perl is faster than ksh. If so, how can we do the
> above operation using perl. I dont think using the above statement
> directly inside perl script as
>
> `cat file_list | xargs -L 500 egrep -ci "pattern_to_search" /dev/null
> | grep -v "0$" | sort -b -t ":" -k4,4 -T "/tmp" > "summary_file"`
> `cat file_list | xargs -L 500 egrep -A3 -i "pattern_to_search" | cut -
> c1-1024 > "detail_file"`
>
> is the right way. Any suggestions and pointers is appreciable.
You can open a file with open, see perldoc -f open.
You can read its contents with the <> operator, see perldoc perlop.
You can filter a list with the grep function, see perldoc -f grep, and
perldoc perlretut.
You can sort a list with the sort function, see perldoc -f sort.
You can extract a piece of a string with the substr function, see
perldoc -f substr.
If you have tried to put these pieces together and can't make it work,
post what you have and we'll help you fix it.
Ben
--
Razors pain you / Rivers are damp
Acids stain you / And drugs cause cramp. [Dorothy Parker]
Guns aren't lawful / Nooses give
Gas smells awful / You might as well live. ben@morrow.me.uk
|
|
|
|
|