in reply to Re: Need help in data processing
in thread Need help in data processing

Hi achak01,

This might work for you

#!/usr/bin/perl use strict; while(<DATA>){ if (m/^Script.+\sat\s(.+)\s(.+)$/){ my $date = $1; my $time = $2; print "$date\t$time\n"; } } __DATA__ Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 +14:36:48 blah blah blah Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 +14:36:48 blah blah blah

Cheers

Replies are listed 'Best First'.
Re^3: Need help in data processing
by achak01 (Initiate) on Feb 26, 2011 at 13:09 UTC
    Sorry! but this sol deosnt seem to work

      Ah I see, one of the times is on a new line. That wasn't immediately clear. Sorry. You could maybe use this although I've not tested it on a large file.

      #!/usr/bin/perl use strict; my $data = do { local $/ = undef; <DATA>; }; while ($data =~ m/Script.+\sat\s(.+)\s(\n)?(\d+:\d+:\d+)/g){ my $date = $1; my $time = $3; print "$date\t$time\n"; } __DATA__ Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 +14:36:48 blah blah blah Script /opt/OV/bin/OpC/agtinstall/inst.sh invoked by root at 02/25/11 14:36:48 blah blah blah

      Cheers