title: Using grep to get the line number of first occurrence of a string in a file
body: <p>I am using bash script for testing purpose.During my testing I have to find the line number of first occurrence of a string in a file. I have tried "awk" and "grep" both, but non of them return the value.</p>
  
  <p>Awk example</p>
  
  <pre><code>#/!bin/bash
  ....
  VAR=searchstring
  ...
  cpLines=$(awk '/$VAR/{print NR}' $MYDIR/Configuration.xml
  </code></pre>
  
  <p>this does not expand $VAR. If I use the value of VAR it works, but I want to use VAR</p>
  
  <p>Grep example</p>
  
  <pre><code>#/!bin/bash
  ...
  VAR=searchstring    
  ...
  cpLines=grep -n -m 1 $VAR $MYDIR/Configuration.xml |cut -f1 -d: 
  </code></pre>
  
  <p>this gives error line 20: -n: command not found</p>