I have the code, for example:
XYZ=5
ABC=`grep -e '^$XYZ,' x-ref | cut -f 2,3 -d , | sed -e 's/,/ #/'
echo $ABC
I have gotten creative in using escapes `\' and also brackets `{}', and combinations thereof. I want to use the variable in the grep statement.
The line in x-ref I want to retrieve is something like:
5,Carroll,064
Giving a result of "Carroll #064"
If I go out to a command-line and type:
grep -e '^$XYZ,' x-ref | cut -f 2,3 -d , | sed -e 's/,/ #/
It works just fine and brings me the result I want, but that is the problem, I need it in a script.
I was wondering how to escape out the '^$XYZ,' in grep, I have also used various -E, -F, egrep, and stuff. I was also curious, although I have found no concrete literature about this, if regexp or grep is treating the value of the variable as a field value.
The ultimate goal is having it in a larger script where the variables value will be a new incremented number in every pass.
I have used google.com to check this forum and others and have yet to find an answer. I am using SCO UNIX OpenServer 5.0.6, also this will be running on umm..., 5.0.5 and 5.0.2? versions so if anyone knows of issues with those they would be greatly appreciated also. I am not opposed to other utils for the purpose but using perl is not possible right now.