1

i need to fetch n+9th line from the occurance of a specific word which is store in variable i from a file LIST.txt

Below is the command

Used_pages=`awk '/${i}/{nr[NR+9]}; NR in nr'  LIST.txt`

it works when i do a test run on the file by replacing the variable $i with one of the values like

 awk '/APPLE/{nr[NR+9]}; NR in nr'  LIST.txt

Please help me figgure out how to use the same command with the variable.

Thanks

1 Answers1

2

awk has the -v parameter for setting variables. To set the variable $i in awk, you would say awk -v i=$i and then within the awk statement, simply reference the variable as i rather than $i.

I haven't tested the following, but try this:

used_pages="$(awk -v i=$i '/i/{nr[NR+9]}; NR in nr' LIST.txt)"
rubynorails
  • 2,293