OfficeLinebacker has asked for the wisdom of the Perl Monks concerning the following question:
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.inpSo 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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing a list of files to see if any contain any one of a list of comma delimited strings
by graff (Chancellor) on Apr 21, 2006 at 01:56 UTC | |
by OfficeLinebacker (Chaplain) on Apr 21, 2006 at 13:39 UTC | |
by graff (Chancellor) on Apr 22, 2006 at 06:19 UTC | |
|
Re: Parsing a list of files to see if any contain any one of a list of comma delimited strings
by GrandFather (Saint) on Apr 20, 2006 at 22:28 UTC |