title: Looping through fields in awk
body: <p>Suppose I have the following three lines in a text file:</p>
  
  <pre><code>I have a dog 
  The dog is goood
  The cat runs well
  </code></pre>
  
  <p>Now I need to go through the file. And print the lines where the word <code>dog</code> occurs along with the field no in which it occurs. I need to accomplish this through <code>awk</code>.</p>
  
  <p>Is there any way by which while processing a line I can sequentially increase the field number, something like the following:</p>
  
  <pre><code>more abc.txt | awk ' j = $NF for (i =1 ; i&lt;= j ; ++i) if ( $N$i == "dog") n= $N0" "$i '
  </code></pre>
  
  <p>How to loop through the fields of a line in awk?</p>