Ok, the title is kind of a tongue twister, so let me start from the beginning:

The people who maintain the databases here have decided that a group of about 30 or so series will be moved to another database. So I need to find all the programs that refer to those series and fix them. I'm only worried about the finding them part right now. So the first step was to do a grep like this:

fst/prod1% find . -name "*.inp" |& grep inp | xargs grep -li '\$open yields'
./CDS/default/uncertainty/i_fin.inp
...snip snip....
./stressind/UpdateReport.inp
./stressind/finfrag1.inp
./stressind/setupdata2.inp
So now I have the list of files I want to search, and a comma delimited list of the series (strings) I want to search for....there may be some linefeeds in there that I want to strip out:
    AAA10YR.B, AAA20YR.B, AAA2YR.B, AAA30YR.B, AAA5YR.B, AA7YR.B, HYTELECOMB2.B, HYTELECOMTAU1.B

etc.

I'm thinking that there has got to be a better way than to brute force it (ie, use X*Y loops where X is the number of files and Y is the number of elements in the comma-delimited list).

This may not even be a Perl problem, but something that can be solved by grep, but I humbly submit my problem to my fellow Monks.

Terrence

UPDATE:

I suppose I could take the comma-delimited list, place each item on its own line, escape the periods, and surround each element with single quotes, writing the result to a file. Then I could just pipe the output of the grep command through one more grep, using the -f (get regexps from a file) option?

UPDATE2: I have to admit I did it in the manner proposed by the first update; I felt that running commands at the prompt one-by-one was easier (remember laziness is a good trait in programmers!) and as stated below, I could track my changes as I applied them rather than writing a whole program and hoping it worked.

The next thing I would like to try is to learn how to do anything sed can do with Perl command-line statements. Any pointers on where I can get to that (also, I am assuming it's possible, since perl was(is?) advertised as a replacement for sed and awk).

I'll go ahead and super search for sed, so don't troubel to respond if you think I'll find it OK.

Thanks again, T.


In reply to Parsing a list of files to see if any contain any one of a list of comma delimited strings by OfficeLinebacker

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.