I am using a bash script for testing purposes. During my testing, I need to find the line number of the first occurrence of the line in the file. I tried awk and grep both, but they do not return a value.
Awk example
#/!bin/bash .... VAR=searchstring ... cpLines=$(awk '/$VAR/{print NR}' $MYDIR/Configuration.xml
it does not extend $ var. If I use the VAR value, it works, but I want to use the VAR
Grep example
#/!bin/bash ... VAR=searchstring ... cpLines=grep -n -m 1 $VAR $MYDIR/Configuration.xml |cut -f1 -d:
this gives error line 20: -n: command not found
grep awk
user1651888
source share