#!/usr/bin/perl $DEBUG = 0; %MSG = () ; usage() unless( @ARGV ); for $file ( @ARGV ) { print "parsing $file ...\n" if $DEBUG ; # open(FH, "<:utf8", $file ); open(FH, "< $file" ); my $content = join( '', ) ; close(FH); while( $content =~ /()/sg ) { my $msg = $1 ; my $datetime ; if( $msg =~ /DateTime="([\d\w-:\.]+)"/ ) { $datetime = $1 ; } else { print "Error parsing DateTime in [$msg]\n"; } print "[$msg]\n" . "="x80 . "\n" if $DEBUG ; $MSG{$datetime}{'msg'} = $msg ; $MSG{$datetime}{'file'} = $file ; } } my @order = sort keys %MSG ; $lastid = 0 ; $lastfile = 0 ; $newid = 0; $newmsg = "" ; for( @order ) { $msg = $MSG{$_}{'msg'}; $file = $MSG{$_}{'file'}; if( $msg =~ /SessionID="(\d+)">/ ) { $sessionid = $1 ; } else { print "Error parsing SessionID in [$msg]\n"; } if( ($sessionid != $lastid) || ($file ne $lastfile) ) { $newid++ ; } $msg =~ s!SessionID="$sessionid"!SessionID="$newid"! ; $lastid = $sessionid ; $lastfile = $file ; $newmsg .= "$msg\r\n" ; print "[$_] : $sessionid ($file)\n" if $DEBUG ; } print "\r\n"; print "\r\n"; print ""; print $newmsg ; print ""; sub usage { print "Usage: $0 file1 file2 file3 ... > newfile\n"; exit(-1); }