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.
In reply to Re: Shorten the headers of a file and remove empty lines using perl
by Preceptor
in thread Shorten the headers of a file and remove empty lines using perl
by intect
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |