in reply to Re: log file sorting
in thread log file sorting
this is relevant part of the program i have so far, which sorts each data label alphabetically. As I was unsure of how to count how many distinct numbers followed a label, i tried to fill in non existant data with substitutions, which was merely a temporary fix. I havent even begun attempting to get the data organized into nice excel-esque columns, as that would first require standardizing its appearance.print "File Location?"; my $data_file = <>; open(RAWDATA, $data_file); my @list; while (<RAWDATA>) { chomp; my (%hash, @rest); ($hash{first}, $hash{date}, @rest) = split(",", $_); for my $r (@rest) { my ($k, $v) = split(' ', $r, 2); $hash{$k} = $v; } push(@list, \%hash); }; my %seen; for (@list) { for (keys %$_) { $seen{$_}++ } }; delete $seen{first}; delete $seen{date}; my @allkeys = ('first', 'date', sort keys %seen); my @keys = (sort keys %seen); open(SEMIDATA, ">temp.slice"); for my $h (@list) { print(SEMIDATA join(',', $h->{first}, $h->{date}, map( $_.' '.$h->{$_} +, @keys ) ), "\n") or warn "print failed: $!"; } close(RAWDATA); close(SEMIDATA); open(EDITDATA, "temp.slice"); my @array_of_data = <EDITDATA>; close ("temp.slice"); foreach my $line (@array_of_data) { #all replacements go here $line =~ s!X!!g; $line =~ s!ART ,!ART / ,!g; $line =~ s!ECG ,!ECG /,!g; $line =~ s!NBP ,!NBP / ,!g; $line =~ s!PA ,!PA / ,!g; $line =~ s!RESP ,!RESP /,!g; $line =~ s!SAO2 ,!SAO2 /,!g; $line =~ s!ST ,!ST //,!g; $line =~ s!TEMP \n!TEMP /\n!g; } # Open the file for writing. open REGDATA, ">temp2.slice"; foreach my $line (@array_of_data) { # Print each line in turn to the new filehandle DATAOUT print REGDATA "$line"; } close REGDATA; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: log file sorting
by moritz (Cardinal) on Aug 04, 2008 at 16:31 UTC | |
by numberninja (Initiate) on Aug 04, 2008 at 17:30 UTC |