Suppose there are a number of files in a directory with a common structure and part of the contents has to be substituted with some other characters for all of the files. The following script may be helpful:
#!/usr/bin/perl -w # # run through all .dat files of the current directory and remove # the string 'mbar' and replace the string 'Pump is off' by '0.' # use strict; my @files = <*.dat>; foreach my $file (@files) { print " converting file $file \n"; my @lines = `cat $file`; # # notice that $line does not contain some copy of a line of @lines # but is pointing to the actual value. # foreach my $line (@lines) { $line =~ s/mbar//g; $line =~ s/Pump is off/0./g; } open FH, ">$file"; print FH "@lines"; close FH; }