Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Copy rows of file to new document by vinoth.ree
in thread Copy rows of file to new document by phineas629

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-23 05:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found