1#! /usr/bin/env perl 2# rpcp - replace text while copy file 3# Copyright (c) 2000 Kriang Lerdsuwanakij 4# email: lerdsuwa@users.sourceforge.net 5# 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program; if not, write to the Free Software 18# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 20$prog_name = "rpcp"; 21$prog_ver = "2.0.0"; 22 23if (@ARGV != 3) { 24 print "$prog_name $prog_ver\n"; 25 print "usage $prog_name RPCP INFILE OUTFILE\n"; 26 exit 0; 27} 28 29@key = (); 30@replace = (); 31 32open INFILE, $ARGV[0] or die "$prog_name: cannot open $ARGV[0] for reading\n"; 33while (<INFILE>) { 34 @list = split ' ', $_; 35 push @key, $list[0]; 36 shift @list; 37 push @replace, join ' ',@list;; 38} 39close INFILE; 40 41open INFILE, $ARGV[1] or die "$prog_name: cannot open $ARGV[0] for reading\n"; 42open OUTFILE, ">$ARGV[2]" or die "$prog_name: cannot open $ARGV[0] for writing\n"; 43while (<INFILE>) { 44 for $i (0 .. scalar(@key)-1) { 45 s/$key[$i]/$replace[$i]/g; 46 } 47 print OUTFILE $_; 48} 49close INFILE; 50close OUTFILE; 51