0

If I want to compare column 6(Comma delimited) with shell variable. But it's not returning anything when I try to compare.

awk -F ',' '$6 == "$grep_value" {print $5}' file ## does not return value 
awk -F ',' '$6 == "abc" {print $5}' file ## returns value

When i try to awk values, it's returning values. I referred following links, but it did't help. awk print column $3 if $2==a specific value? How to use shell variables in an awk script

Community
  • 1
  • 1
Hideandseek
  • 271
  • 1
  • 4
  • 17
  • You seem to have missed the point of the linked articles as you're using shell variables in totally the wrong way! – Tom Fenech Jan 26 '16 at 17:25
  • Did't get you. Can you explain more? @TomFenech – Hideandseek Jan 26 '16 at 17:27
  • Use the format in the accepted answer to the linked question: `awk -F ',' -v grep_value="$grep_value" '$6 == grep_value {print $5}' file` – Tom Fenech Jan 26 '16 at 17:29
  • I have spaces in my column values. It's throwing "ambiguous redirect" error. Can you help? @TomFenech – Hideandseek Jan 27 '16 at 05:57
  • It's unclear how the code in the question or the suggestion made in the comments would lead to that error. If you have resolved the issue of using shell variables in awk (as covered in the linked question) but have a different problem, then maybe you should ask a new question showing a reproducible case that we can help you with. – Tom Fenech Jan 27 '16 at 09:47

0 Answers0