Happy New Year Monks!
My question and code posted below. I would like to delete the SAME line in multiple files. The below code works fine for 2 files however I have an additional 3 files or more the data could show up in but not always. Instead of listing each file is there away to combine EVERYTHING into one block of code? Thanks for the help!
my $process_file = $rrconfig::locodata; my $process_file2 = $rrconfig::availlocodata; my @data; my @data2; { open(my $data_file_handle, '<', "$process_file") or die("Can't open file: $process_file"); open(my $data_file_handle2, '<', "$process_file2") or die("Can't open file: $process_file2"); @data = <$data_file_handle>; @data2 = <$data_file_handle2>; close($data_file_handle); close($data_file_handle2); close $process_file; close $process_file2; } chomp(@data); chomp(@data2); open(my $out_file_handle,'>', $process_file) or die("Can't open file: $process_file"); open(my $out_file_handle2,'>', $process_file2) or die("Can't open file: $process_file2"); foreach my $line_from_file ( @data ) { my @field = split( /\:/, $line_from_file ); next if( ($field[1] eq $delroad) && ($field[2] == $delnumber) ); print $out_file_handle $line_from_file, "\n"; } foreach my $line_from_file2 ( @data2 ) { my @field2 = split( /\:/, $line_from_file2 ); next if( ($field2[1] eq $delroad) && ($field2[2] == $delnumber) ); print $out_file_handle2 $line_from_file2, "\n"; } close $out_file_handle; close $out_file_handle2; close $process_file; . close $process_file2;
In reply to Delete Lines Across Multiple Files by PilotinControl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |