Hi Perl Guru's

I have a requirement where i need to find out two patterns and second pattern is dependent on first pattern (i.e., if file1 have pattern1 the serach pattern2 in file1). Let me explain in detail.

Forexample: I have last three days job logs (Infact logs folder have more then 1000 differnt log files), I have pattern1 "ABC_DEF" and pattern two looks like "GHI JKL".

--> Serach Pattern1 in all three days logs
--> Pattern1 will point out all required logs
--> Then serach pattern2 in all logs which we have indentified based on Pattern1.
--> Print all Matched patterns1 and Print all Matched patterns2

Could you guys please help me out to solve this issue..?

Thanks in advance.

Recommended Answers

All 3 Replies

The simplest way to handle this is as follows:

1. opendir/readdir the logs folder, save the file paths to @log_files
2. foreach @log_files, open file, then search it for the pattern
3. if found, push file path to @found_patterns
4. then, search file for 2nd pattern, push to @found_patterns2 on success
5. assuming files are not huge, you can slurp the file first:

open my $fh, "<", "foo" or die $!;
local $/; # enable localized slurp mode
my $content = <$fh>;
close $fh;

then you can match both patterns against $content

Hi erezschatz ,

I have tried this but this is not helping me out.
Could you please elaborate in more depth..?

Thanks

Hi erezschatz ,

I have tried this but this is not helping me out.
Could you please elaborate in more depth..?

Thanks

I could, probably, but it would be better if you can post the code you wrote, along with some test data and what results you get/don't get and we'll continue from there

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.