0

I have a following file.

cat test.txt
NE|East
OR|East
WB|East
HP|North
HR|North
JK|North
NR|North
PB|North

I have a variable circle which stores the following value. circle="JK"

Now, I want the value matching my variable. I have used the following code, but it doesn't provide me any output. However, when I manually writes "JK", it shows me the desired result.

awk -F '|' '{if($1==$circle) print $2;}' test.txt

awk -F '|' '{if($1 == "JK") print $2;}' test.txt North

Please suggest. Help is much appreciated.

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
naggarwal11
  • 122
  • 1
  • 14

1 Answers1

1

Could you please try following.

val="$JK"
awk -v var="$val"  -F'|' '$1==var{print $2}' Input_file
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93