Re: Adding a line in a file inside many directories



Ved wrote:
I have a 150 directories, each having a file "kat.s" in them.
I have names of all these directories in a text file
"list_of_dir.txt".

I have to open the each of "kat.s" in all the 150 directories and add
a line(say "ABCD" at line number 20) in each of them.

<snip>

foreach my $file_list (@rgstr) {
print $file_list ; #printing list of dir

open (dirIN, '$file_list/kat.s') or die "Cannot open 'File.txt' $!";
#This is not working

open (dirIN, "$file_list/kat.s") or ...

But that will only open the file for reading. Furthermore, since you want to add a line at a specific position in the file, I think you should consider the advice in this FAQ entry:

perldoc -q "insert a line"

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages