Question

I have a file One.lst that has the following content:

a
b
c

Now,i have to search in :

a_man.lst
b_man.lst 
c_man.lst 

the pattern : <inc>true</inc>.

Now,suppose b_man.xml has the above pattern.

So, I have to log b in another file, say Two.lst.

Was it helpful?

Solution

You can for example do:

while read line
do
    grep -q "<inc>true</inc>" ${line}_man.lst && echo $line >> Two.lst
done < One.lst
  • The while read keeps reading the file names from One.lst and stores them in $line.
  • grep -q checks the existence of <inc>true</inc> in ${line}_man.lst. In case of match, it prints the file name ($line) into Two.lst.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top