in reply to reading file in directory
#!/usr/bin/perl -w my ($dir,$file,$old,$new); print "Enter filename: "; $file = <STDIN>; print "Enter the name of output file: "; $out = <STDIN>; print "Enter old pattern: "; $old = <STDIN>; print "Enter new pattern: "; $new = <STDIN>; chomp ($file,$old,$new, $out); open (OUT, ">>$out") || die $!; opendir (DIR, ".") || die $!; my @files = readdir(DIR); open (FH, "$file") || die "cant open file $!"; my @lines = <FH>; foreach my $line (@lines) { if (grep /$old/,$line) {$line =~ s/$old\s/$new/g;} print OUT $line; }
|
|---|