Search code examples
linuxparsingloopsindices

awk error with indice when used in a loop


I have the follwing situation.

 awk '$0 != "Force for tool binder"   # print all lines until string found
 $0 =="Force for tool binder"{
 print ; getline ; print;            # go to 2 lines below the string
 getline; getline < " forceState$j.k "; print}' dynaFile_Offen1.k > tempDynaFile.k   # take the string from 
 #the file forceStates$j.k and replace in the main file, generating a temp file.

The problem is that here the j is a loop index, meaning that for the first case it is j=1. when I used it as forceStates1.k it works perfect but in the loop it is not taking the value.

I would be obliged for the suggestions.


Solution

  • $j in '... " forceState$j.k " ...' will not get expanded.
    Is it a problem?