I'm trying to display the line number of the first 'string' occurrence from a long string variable and set the result to another variable.
To display the line of the first 'string" occurrence, I use:
grep -n -m 1 String Filename.csv | cut -f1 -d:
It works fine. However, I would like to get the 'String' value from the array variable and Filename.csv switch to the long string. For example:
string[0]='Column2'
Query="Select Column1,
Column2,
Column3
From dual"
And now:
Line_number=$(grep -n -m 1 ${string[0]} "$Query" | cut -f1 -d:)
echo $Line_number
The result should be: 2
But it displays:
grep: "Select Column1,
Column2,
Column3
From dual " No such file or directory
What's wrong?