Are you writing a perl script to do this because you don't have unix tools like "grep"? (There's no good reason why you should lack those tools.)
# shell command, assuming there are not tons of files in file_path: grep -h ^CQA_STATUS file_path/cqa_* > file_path/CQA_STATUS # but if there are tons of files, do it like this: find file_path -name 'cqa_*' | xargs grep -h ^CQA_STATUS > file_path/C +QA_STATUS # (update: added carets where needed)
Now, if these files had two or more lines starting with CQA_STATUS, and you only wanted to extract one of those lines, then you'd probably want a perl script -- and yes, you would want to go ahead and open each file in turn, and use perl's grep function (and/or whatever else is necessary to pick the particular line you want) in order to extract the target line from each file. Something like:
open( O, ">", "file_path/CQA_STATUS" ) or die "CQA_STATUS: $!"; for my $file ( <file_path/cqa_*> ) { open( I, "<", $file ) or do { warn "$file: $!"; next }; while (<I>) { # suppose we only want the first occurrence from eac +h file if ( /^CQA_STATUS/ ) { print O; last; } } close I; } close O;

In reply to Re: extract a single line from multiple files in a folder. by graff
in thread extract a single line from multiple files in a folder. by august3

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.