Reputation: 87
awk -F"," -v var=$test '$1 ~ /^var$/{print}' alpha.txt
I tried hard-coding my var with my actual variable input and I found that this code works. However, when I tried for example /^ppl$/
to search for partial match of apple, it does not display. can someone give me some guidance as to how I can parse my variable into the command?
Upvotes: 3
Views: 961
Reputation: 246754
If you're anchoring the match at the beginning and the end, just use ==
awk -F"," -v var=$test '$1 == var' alpha.txt
Unless $test
contains a regular expression, in which case @Kent has the right answer.
Upvotes: 0