Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use awk -v 1

Status
Not open for further replies.

prosper

Programmer
Sep 4, 2001
631
HK
I am writing a bash script to call awk -v.
The following is the bash script
Code:
inp='sles10'
result=$(awk -v var1=$inp '$1~/^$var1$/ {print$2}' /etc/testtext)
echo $result
I want to pass a variable from bash to awk to match against the first column of the file and display the content of second column if it is matched exactly.
Thanks for any help
 
Replace this:
$1~/^$var1$/
with this:
$1==var1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It works. Thanks PHV
I want to ask if
$1~/^var1$/ has syntax error
Thanks
 
No syntax error, but evaluates if $1 equal to the literal "var1".

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top