in reply to Copy rows of file to new document
Just giving you an idea
Assuming you files are text files
1.Opening the directory which contains your 300 files using the opendir() function#!/usr/bin/perl use strict; use warnings; my $dir_path="Your Directory Path"; opendir (DIR, $tmp_dir) or die $!;
2.Open the destination file with the appending modeopen() function
open (MYFILE, '>>data.txt');
3.Reading each files using the readdir function. readdir returns the name of each file or directory in the opened directory in turn when used in scalar context, or a list of the names of all files and directories in that directory when used in list context.
while (my $file_name = readdir(DIR)) {print "$file_name\n";}
4.Within this loop open each file in read mode and do another loop to each all the content and check for whatever the word match you need with regular expression. If matches write that content into the "data.txt" file as print MYFILE $file_content; Once each file completes close each file respectively close (MYFILE);
use the function closedir function to close the opened directory
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Copy rows of file to new document
by phineas629 (Novice) on Jan 25, 2013 at 02:12 UTC | |
by choroba (Cardinal) on Jan 25, 2013 at 09:25 UTC | |
by phineas629 (Novice) on Jan 25, 2013 at 21:32 UTC | |
by choroba (Cardinal) on Jan 25, 2013 at 21:49 UTC |