My first thought would be to use an XML parser (as previously suggested), but choroba has good point about XML format. Although it's not a one liner, I believe that the untested code below should do the trick.
use strict; my $ip = '10.146.163.43'; my $logfile = "logfile.log"; my $log; open(LOG,"<",$logfile) || die "Unable to open file '$logfile': $!\n"; { local $/; $log = <LOG>; # slurping file into $log } close(LOG); $log =~ m/(<request>.*?$ip.*?\/request>)/is; print "Log for IP address $ip:\n\n$1\n";
If you're on a *nix OS, you'll probably need to add the appropriate #! line at the top. I do most of my Perl stuff on Windows and haven't gotten in the habit of adding that line to my code.
In reply to Re: How i can extract the part of server report log based on Ipaddress
by dasgar
in thread How i can extract the part of server report log based on Ipaddress
by perladdict
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |