regex - Rename the text file -
i have multiple text files different names in directory. want search string in text files , if string found in text file , want rename text file abc.txt
can me in doing perl script.
this ought you're looking for.
you should spend time , figure out how works.
"i want rename text file abc.txt"
hopefully aware can have one
file named abc.txt
in same directory. i'm making files: abc.txt abd.txt abe.txt
, on...
this untested btw...
#!/usr/bin/perl use strict; use warnings; use autodie; use file::copy; $dir = "test-dir"; opendir(my $dh, $dir); chdir $dir; @files = grep { !-d $_ } readdir $dh; closedir $dh; $new = "abc"; $file (@files) { open $fh, "<", $file; while(my $line = <$fh>) { chomp $line; if($line =~ /something/) { move($file, "$new.txt"); $new++; last; } } close $fh; }
Comments
Post a Comment