Adding a line in a file inside many directories
- From: vedpsingh@xxxxxxxxx (Ved)
- Date: Thu, 28 Jun 2007 19:00:51 -0000
Hi All,
Situation is bit complex (atleast for a beginer like me).
Directory structure is somewhat like this:
testcases--> 150 Directories (names starting with mixed or green.) ---
kat.si.e. a directrory named testcases has 150 number of directories in it
and each of those 150 number of directories has a file named kat.s .
Now I have to print a single line at say line number 20 in each of 150
number of kat.s file.
I also have a list of names of all 150 subdirectories in a text file
named "list_of_files".
I have thought of implementing like this:
Open all kat.s in all the 150 directories using "list_of_files" and
print the line(tried as in code below).
There is some problem in line where I am trying to open kat.s using
dirIN handle.
What am I doing wrong ?
Is there any better approach ?
#########
use strict;
use warnings;
my $file = 'print.txt';
open my $VEDOUT, '>', $file or die "Could not open '$file': ";
open (VEDIN, 'list_of_files.txt') or die "Cannot open 'File.txt' $!";
my @rgstr=<VEDIN>;
foreach my $file_list (@rgstr) {
print $file_list ; #prints file list
open (dirIN, '$file_list/kat.s') or die "Cannot open 'File.txt' $!";
#How to open kat.s ??
###Further have to add the print statement
}
close (VEDIN);
close ($VEDOUT);
##########
Regards
Ved
.
- Follow-Ups:
- Re: Adding a line in a file inside many directories
- From: usenet
- Re: Adding a line in a file inside many directories
- Prev by Date: SOLVED - Re: Tie::Handle::CSV
- Next by Date: Need idea for doing automatic iteration, please.
- Previous by thread: missing curly - brain fried
- Next by thread: Re: Adding a line in a file inside many directories
- Index(es):