in reply to Multiple Search and Replaces on one file

I would do something like the foloowing:
my $file = 'tmp.txt'; my $out = 'out.txt'; open(FILE, "<", $file) || die "Can't open $file: $!\n"; open(OUT, ">", $out) || die "Can't open $out: $!\n"; while(<FILE>){ s/(\d+\/\d+\/\d+).*?(%PIX.+)/$1 $2/g; s/\// /g; s/\w+\:(\d+\.\d+\.\d+\.\d+)/$1/g; print OUT $_; } close FILE; close OUT;

Avoiding the hash and using the numeric date already in each log entry is probably the best way.

Edit: Typo corrected.

Replies are listed 'Best First'.
Re^2: Multiple Search and Replaces on one file
by fishbot_v2 (Chaplain) on Jun 15, 2005 at 19:32 UTC

    ...but in his example line the first date-time string and the second are -clearly- different. The month happens to be the same in that example. You are taking the date from the first stamp and the time from the second.

    Also there is a missing '.' from your first regex.

      Your making an assumption that each log entry does not have the same syntax. I am making the assumption that it does because that is what the OP's example shows. Where do you get your info from?

      Also I am not missing anything from my regexp. Maybe you think my example was trying to match something it was not.

        Here is his example:

        6/13/2005 5:59:57 PM 10.1.1.2 WARNING Jun 13 2005 22:00:04: %PIX-4-106 +023: Deny udp src aliens:192.168.1.35/1148 dst dmz:10.10.10.32/1434 b +y access-group "aliens"
        He said that he wanted to convert the Jun (in the second timestamp) to 06. Earlier in the log entry, there is another timestamp. The first timestamp appears to be from 5:59 pm, the second around 10:00 pm. You are making the assumption that the two datestrings in the log file are identical and interchangable.

        Regex error: "(%PIX+)" this matches what? "%PIX" and then an unlimited number of Xs? You surely mean "(%PIX.+)", since the way you have it deletes everything in his example log entry after the 'X'.