print the next line by searching with different patterns

Hi,

I am having an '.xml' file with 'n' number of lines and also having another file with '.txt' format contains values which i want to search.

Now I want to print the next line with the pattern which i am searching in '.xml' file. And the loop has to repeat for different patterns which are present in '.txt' file.

the logic which i used is

  while read line
  do 
    awk -f '/$line/ {for(j=1; j<=1; j++) {getline; print}}' sample.xml >> output.txt
  done< values.txt

for the above logic i am getting error as

awk -f '/$line/ {for(j=1; j<=1; j++) {getline; print}}' sample.xml
awk: fatal: can't open source file `/$line/ {for(j=1; j<=1; j++) {getline; print}}' for reading (No such file or directory)

in this logic, the value is reading by the variable 'line' and it is not evaluating in the awk cmd.

Can anyone advise on this?

if your fgrep supports -A option, then

 
fgrep -f values.txt -A 2 sample.xml

your awk command correction

awk -v l="$line" '$0~l{print;getline; print}' sample.xml

Thanq raj !!

I corrected my awk command, but again i am getting the error as

awk -v $'l=SharedResources/JMS/username\r' '$0~l{print;getline; print}' ./sample.xml

I didnt understand the flow of awk command which you corrected.

And also i tried with the fgrep command, i am not getting any output and error as well.
can you please help me on this...

The syntax should be

-v l='some extended regular expression'

Actually in my .txt file i am having the values in the below format,

'abc/asd/zxw'

with these type of patterns, i have to search in .xml file and print the consecutive line.

Did you try to use l='abc/asd/zxw' ?