#!/usr/bin/perl -w # parse a log file and move lines with important text to top # of file while keeping sequence within each of two sections: # important and not-so-important use strict; my $infile = '/dir/file.in'; my $outfile = '/dir/file.out'; my @important; my @normal; open IN, "$infile" or die "Couldn't open $infile"; open OUT, ">$outfile" or die "Couldn't open $outfile"; while () { s/unwanted text//g; # strip unwanted text s/more unwanted text//g; # strip unwanted text s/^\s+//g; # remove empty lines (/important text/) ? push @important, $_ : push @normal, $_; } print OUT @important; print OUT @normal; close IN or die "Couldn't close $infile"; close OUT or die "Couldn't close $outfile"; # END