Wednesday, November 16, 2011

Replacing Values in text File

#!/usr/bin/perl -w

# Print the value of the command line arguments
#$numArgs = $#ARGV + 1;
#print "You provided $numArgs arguments\n";
print "Input file is $ARGV[0]\n";
print "Output file is $ARGV[1]\n\n";

# Open input file in read mode
open INPUTFILE, "<", $ARGV[0] or die $!;
# Open output file in write mode
open OUTPUTFILE, ">", $ARGV[1] or die $!;

# Read the input file line by line
while (<INPUTFILE>) {

  $_ =~ s/Fusion.test/sriram.test/g;
  $_ =~ s/weblogin.test/newnewlogin.test/g;
  print OUTPUTFILE $_;
}


close INPUTFILE;
close OUTPUTFILE;

====================================

sriram@ubuntu:~/perl$ ./check.pl value.txt output.txt
Input file is value.txt
Output file is output.txt

sriram@ubuntu:~/perl$

No comments:

Post a Comment