I have a script which reads a number out of a log file. The pertinent line is this:
cat /tmp/listofnumbers
When I run cat /tmp/listofnumbers what I am seeing is [9878] [6376] on each line.
I am trying to make the script read from that file and grep for a variable like the following line should do:
cat /tmp/listofnumbers |grep "\[$var\]"
But that doesn't work. I can echo the variable number but the grep will never return it in the file. I have tried using $( and other tricks but it doesn't work. Any suggestions would be greatly appreciated.
The grep and egrep utilities should treat these expressions the same way. We need to see how you are setting bpx (or in your earlier example var ) and a sample of the lines in your input file that you expect the expression to match to figure our what is really going on here.
I don't think it's a good idea to say "grep doesn't work, but don't know why, but egrep works for some unknown reason, so I'll use egrep". Better to under WHY grep doesn't work for you. There is always a reason. I hope you can find the reason.