On Fri, Mar 14, 2008 at 3:33 PM, Manoj <[EMAIL PROTECTED]> wrote: > I have a log file like this. The part between += are almost similar from > which I need to fetch for IP Address and Connection time only for domain > perl.com. The perl.com domain may scattered in log. The main intension of my > work is that this log keeps a record of the users who visits websites. I > have to get the doc printed that contains specific domain visits and time. > Thought the below one I will take as a sample data. The IP address can be > the 10 or 11th line from Domain line. Was first thinking of getting this by > using head and tail command in unix. This works for me but for windows box > this will be a problem as I don't have cygwin installed which I will not be > able to do. All comments are welcomed. Thanks..! snip
What you need to do is read in the individual records (delimited by "+=========================+\n") and search for the required fields with a regex: #!/usr/bin/perl use strict; use warnings; $/ = "+=========================+\n"; while (<DATA>) { chomp; next unless length > 0; next unless my ($ip, $time) = /Domain : perl\.com.*IP:(\S+).*Connection Time:(\S+)/s; print "$ip $time\n"; } __DATA__ +=========================+ Domain : perl.com hostname .... .... IP:XXX.XXX.XXX.XXX Connection Time:XXX secs .... .... .... .... +=========================+ Domain : domain.com hostname .... .... IP:XXX.XXX.XXX.XXX Connection Time:XXX secs .... .... +=========================+ Domain : education.com hostname IP:XXX.XXX.XXX.XXX .... .... Connection Time:XXX secs .... .... +=========================+ Domain : perl.com hostname IP:XXX.XXX.XXX.XXX .... .... Connection Time:XXX secs .... .... +=========================+ -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/