in reply to Need help in data processing

You start by reading perlintro, it walks you through perls basic syntax, including basic file i/o and basic pattern matching. Then , as How do I post a question effectively? says, you show your code :)

Replies are listed 'Best First'.
Re^2: Need help in data processing
by richardwfrancis (Beadle) on Feb 26, 2011 at 08:59 UTC

    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

      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