In my bash script I have a variable that I am trying to pass to a pattern to search for using awk. However what I expected to happen is not working. I have the following text file (text.txt):
-----------
Task: a
(some info)
....
------------
Task: b
(some info)
....
------------
Task: c
(some info)
....
------------
My script has the following:
letter=a
awk -v var="$letter" '/Task .* \var/' RS='-+' text.txt
When I do this however I get nothing but if I do the following:
awk '/Task .* a/' RS='-+' text.txt
I get what I expect:
Task: a
(some info)
....
NOTE: I need to pass it as a variable because I have a loop that is constantly changing the variable and that's what I am trying to look for. I'd rather use awk since that what I am most familiar with but I am not opposed to hearing other suggestions such as sed or grep.
-v var="$var"
– 123 Jul 16 '15 at 13:36