I am trying figure out how I can ask a user for input, use the input as the pattern to match with grep, and return the line number to a variable.
echo "What BCP do you want?"
read BCPid # Get what value we're interested in.
for i in *.txt
do
BCPlinenum=$(echo "$BCPid" | (grep -n "$BCPid" |cut -f1 -d:))
echo "$BCPlinenum"
done
This returns a value of 1, regardless of what I input.
The file it searches looks as follows,
BCP C1 C2
BCP C1 C3
BCP C1 C4
BCP C2 C3
BCP C2 C4
BCP C3 C4
So, the desired function is to input "BCP C1 C2" and have it return 1 (the line number) to a variable.
Thank you!