Looks like I was able to figure it out with the below:

But how do I remove all the blank lines?

Output:

cdmno=1
rdnt_cdmno=1







cdmno=2
rcsm=801







rcsm=801







rcsm=802

#!/usr/bin/perl
use warnings;
use strict;

my $file = "nonKeys.txt";
my $newFile = "cleanKeys.txt";
my @keyFields = qw(rcsm cdmno);

#open my $FH, '<', $file or die "ERROR opening $file: !";
open my $FHOUT, '>', $newFile or die "ERROR opening $newFile: !";

while ( <DATA> ) {
  chomp;
  for my $i ( 0 .. $#keyFields ) {
    $_ =~ s/$keyFields[$i]\d.*//;
  }
  print "$_\n";
}
__DATA__
cdmno=1
rdnt_cdmno=1
cdmno2=1
cdmno3=1
cdmno4=1
cdmno5=1
cdmno6=1
cdmno7=1
cdmno8=1
cdmno=2
rcsm=801
rcsm2=801
rcsm3=801
rcsm4=801
rcsm5=801
rcsm6=801
rcsm7=801
rcsm8=801
rcsm=801
rcsm2=801
rcsm3=801
rcsm4=801
rcsm5=801
rcsm6=801
rcsm7=801
rcsm8=801
rcsm=802

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to