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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk parsing with variable 2

Status
Not open for further replies.

jmc0031

IS-IT--Management
Sep 12, 2011
6
0
0
FR
Hi,

I would like to parse a fic with awk variable but i have a problem

My FIC :
Test1 1100
Test2 0011
Test3 011A
Test4 BB23

The result that i want :
Test1 1100

A script that work great :
Code:
awk '$2 ~ /^11/ {print $0}'

But i want to use a variable like HEXA=11
This not work like i want :
Code:
awk '$2 ~ var {print $0}' var=$HEXA

the result is
Test1 1100
Test2 0011
Test3 011A
and i want just : Test1 1100

I would like to filter the 2 first digit with my variable.

I hope my problem is clear ...

Thanks
 
What about this ?
awk '$2 ~ /^'$HEXA'/'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or:

Code:
awk '$2 ~ var' var="^$HEXA"

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Hi

The 2 solutions work great

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top