I need to find out what is the line number of first occurrence of a given search string that should be in the start of a line in a text file and store it in a variable in my bash script. For example I want to find the first occurrence of "c":
abc
bde
cddefefef // this is the line that I need its line number
Casdasd // C here is capital, I dont need it
azczxczxc
b223r23r2fe
Cssdfsdfsdf
dccccdcdcCCDcdccCCC
eCCCCCC
I came up with this but as you see there are big problems
trimLineNum=$(cat "${varFileLog}" | grep -m1 -n "c")
echo "c is at line #"${trimLineNum}
The output will be:
c is at line #1:abc
Problems:
- So obviously it matches the first line, because there is a "c" in the line.
- The output will also include the content of the line as well! I want it to be just the number of the line
what should I change to fix those problems?