On Friday, April 12, 2002, at 09:09 AM, Guan Boon Lee wrote:
> I would like to find a word or character in a file and > replace it with another word or character, while > leaving others untouched. Currently, I am using the > following method > > #!/bin/perl -Dr -w > open(FILE,"$ARGV[0]") || die "Can't open $ARGV[0]: > $!\n"; > open(FILE2,">$ARGV[0].spi") || die "Can't open > $ARGV[0]_new: $!\n"; > while (<FILE>) > { > if (/(^VV\d+ )(TA)x(\d)x(.*)/) > { > print FILE2 $1,,$2,"[",$3,"]",$4,"\n"; > } > else > { > try this here to only do replace in lines that aren't found in the 'if' clause: s/$searchword/$replaceword/; do the substitution regex before the 'if' to do it in either case. > print FILE2 $_; > } > } > close FILE; > close FILE2; > > Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]