Guest User

Untitled

a guest
Apr 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. use strict;
  2. use warnings;
  3.  
  4. if (@ARGV != 2){# Test for correct number of arguments
  5. print "This script takes exactly 2 arguments";
  6. exit;
  7. }
  8.  
  9. # Open input and output files
  10. open(my $in, "<", $ARGV[0]) or die "Can't access input file: $!";
  11. open(my $out, ">", $ARGV[1]) or die "Can't write output file: $!";
  12.  
  13. while (<$in>) {# Loop over the lines of the input file
  14. if(/text1/i) {# check if line contains "text1"
  15. s/text1/replaced/gi # replace all instances of "text1" with "replaced"
  16. }
  17. print $out $_ # Write the modified line into the output file
  18. }
  19.  
  20. perl myscript.pl inputfile.txt outputfile.txt
  21.  
  22. for %f in (*.txt) do perl myscript.pl %f %~nf_out.txt
Add Comment
Please, Sign In to add comment