Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- if (@ARGV != 2){# Test for correct number of arguments
- print "This script takes exactly 2 arguments";
- exit;
- }
- # Open input and output files
- open(my $in, "<", $ARGV[0]) or die "Can't access input file: $!";
- open(my $out, ">", $ARGV[1]) or die "Can't write output file: $!";
- while (<$in>) {# Loop over the lines of the input file
- if(/text1/i) {# check if line contains "text1"
- s/text1/replaced/gi # replace all instances of "text1" with "replaced"
- }
- print $out $_ # Write the modified line into the output file
- }
- perl myscript.pl inputfile.txt outputfile.txt
- for %f in (*.txt) do perl myscript.pl %f %~nf_out.txt
Add Comment
Please, Sign In to add comment