in reply to Shorten the headers of a file and remove empty lines using perl
What you need to accomplish this is regular expressions. Learning regular expressions can be a bit painful, but they're really incredibly powerful. As a sample, the code below might give a start point.
The relevant documentation is perlre
open ( my $input_fh, "<", $input_file ); open ( my $output_fh, ">", $output_file ); foreach my $line ( <$input_fh> ) { unless ( $line =~ m/\A\s*\Z/ ) { $line =~ s/(GL\d{6}))\d+/$1/; print $output_fh $line; } } close ( $input_fh ); close ( $output_fh );
The essence is - first you test if a line is blank. Then you use a 'search and replace pattern' to trim any pattern starting GL, followed by 6 digits, to 6 digits.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Shorten the headers of a file and remove empty lines using perl
by Anonymous Monk on Jun 13, 2013 at 22:51 UTC | |
by Cristoforo (Curate) on Jun 13, 2013 at 23:27 UTC | |
by choroba (Cardinal) on Jun 13, 2013 at 23:30 UTC | |
by Preceptor (Deacon) on Jun 14, 2013 at 20:29 UTC | |
by Cristoforo (Curate) on Jun 13, 2013 at 23:43 UTC | |
by Anonymous Monk on Jun 14, 2013 at 01:27 UTC | |
by Preceptor (Deacon) on Jun 14, 2013 at 20:26 UTC |