-3

I need to write the this statement:

cat filename | awk -F '|' '($4 ~ /"$Var_PRJ"/) && ($7 == "Y")'.

However, $Var_PRJ is not getting expanded (may be because awk uses single quotes). How can I get this implemented with actual value of Var_PRJ?

Note: cat filename | awk -F '|' '($4 ~ /1234/) && ($7 == "Y")' is working fine.

Arjun Mathew Dan
  • 5,240
  • 1
  • 16
  • 27
Sumit
  • 245
  • 1
  • 3
  • 10

1 Answers1

-1

This will do the trick

awk -F '|' '($4 ~ /'"$Var_PRJ"'/) && ($7 == "Y")' filename

Notice double quotes before and after BASH variable

Abhijeet Kasurde
  • 3,937
  • 1
  • 24
  • 33
  • Downvoter please explain reason for downvoting. – Abhijeet Kasurde Oct 24 '16 at 09:50
  • I just downvoted because this would make the shell variable expand to become part of the actual awk script and so lead to cryptic errors (and probably security vulnerabilities). See https://stackoverflow.com/questions/19075671/how-do-i-use-shell-variables-in-an-awk-script. – Ed Morton Sep 09 '19 at 15:11