I am trying to extract information from a file using awk
e.g. My file
Code:
10001 aaa111 bbb222
10002 ccc333 ddd444
10003 eee555 fff666
If I want to extract information of 10001...
Code:
awk '/10001/ { print $1 " " $2 " " $3 }' myfile.txt
The above works. It outputs what i wanted
But if I want to hard code it and pass in the 10001 as a parameter into the script or using a variable...
Code:
mycode=10001
awk '/$mycode/ { print $1 " " $2 " " $3 }' myfile.txt
awk '/$1/ { print $1 " " $2 " " $3 }' myfile.txt
The above does not work. It does nothing and output nothing.
Is there something wrong with it?
I can't figure out why.