If I understand the problem, you have a list of patterns to search for in a set of *.inp files. If you have that list stored in a file, with commas and whitespace as you have indicated, then the script starts by turning that list into a suitable regex pattern. Then it searches for the files where this regex pattern needs to be sought out. Then you'll do something wiht the list of files where the regex matched:
Of course, the original list file (containing the patterns to search for) could be a command-line arg or piped in on this script's STDIN, in which case forget the "open(L,..." statement, and read the regex data with $_ = <>;#!/usr/bin/perl use strict; # get the regex pattern my $regex; open( L, "that.list" ) or die "that.list: $!"; { local $/; $_ = <L>; s/^\s+//; # remove initial whitespace, if any s/[,\s]+$//; # remove final comma and whitespace s/\s*,\s*/\|/g; # convert internal separators to "|" s/\./\\./g; # escape period characters $regex = $_; } close L; # now look for candidate files # (I prefer using unix "find"...) my @found; open( F, "find . -name '*.inp' |" ) or die "find: $!"; while (<F>) { chomp; my $datafile = $_; if ( open( DATA, $datafile )) { local $/; $_ = <DATA>; push @found, $datafile if ( /\$open yields/ and /$regex/ ); close DATA; } else { warn "open failed on $datafile: $!\n"; } } # @found now contains the set of file names that are needed
(It might be good to state the actual path where the target files are supposed to be found, and put that path into the "find" command in the script, rather than assume that the CWD will be the correct one when the script runs.
In reply to Re: Parsing a list of files to see if any contain any one of a list of comma delimited strings
by graff
in thread Parsing a list of files to see if any contain any one of a list of comma delimited strings
by OfficeLinebacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |