Hi all,
I am trying to extract a single line of text from multiple files in a folder. I am trying to do this with out opening the files for reading. Don't know if this is a good idea. The code that I wrote using grep is not working..I would appreciate if you could correct me. The code snippet is provided below. Each file has multiple lines but ONLY ONE line that starts with CQA_STATUS and I am trying to extract ONLY this line.This line is like CQA_STATUS,TEST_NAME,PASS,FAIL,PASS,FAIL,FAIL,FAIL,PASS
Thanks
august
my $usage = "usage: get_cqa_status.pl <cqa_file_path>"; my $cqapath = ""; my $status_line = ""; ############################################ if ($#ARGV <0) { die "$usage"; } $cqapath = $ARGV[0]; my @cqafiles = glob("$cqapath/cqa_*"); open (FILE, "> $cqapath/CQA_STATUS")||die "can't open file $cqapat +h/CQA_STATUS for writing.\n"; foreach my $item (@cqafiles) { my @stats = grep ('CQA_STATUS', $item); $status_line = $stats[0]; #Remove everything before the first comma #$status_line = substr($status_line, (index $status_line, ',')+1); print FILE "$status_line\n"; } close(FILE) || die "can't close$cqapath/CQA_STATUS after writing\ +n";

In reply to 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.