in reply to extract a single line from multiple files in a folder.
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:# 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)
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;
|
|---|