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!

variable in pattern match

Status
Not open for further replies.

cp2000

Technical User
Dec 31, 2002
81
US
I have what appear to be to issues I need to resolve.
1) I need to be able to pass a variable to the pattern match.
e.g awk -F" " '/v1/ {print $3,$4,$5,$6,$7}'v1=$RDSK dumpdates where RDSK="c0t2d0s0 0"

2) As you see my variable (RDSK) has a number spaces in it.

 
Hi:

Read grega's pass variables to awk FAQ:

forum271

Try placing double quotes around your variable:

v1="$RDSK"

Regards,

Ed
 
Try something like this:
Code:
RDSK="c0t2d0s0               0"
awk -F" " "/$RDSK/"'{print $3,$4,$5,$6,$7}' dumpdates

Hope This Help
PH.
 
Or

awk -F" " -v v1=$RDSK '$0 ~ v1 {print $3,$4,$5,$6,$7}' dumpdates


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Thanks peoples...got it working.

olded: I actually started by doigna keyword search and reading the Variable FAQ. That was my adaptation of the examples.

PHV: I'm notsure I understand why the double-quotes on the pattern makes the difference but IT WORKS like a champ...THANKS!!!

CaKiwi: That's like what I would expect to work but.....
-bash-2.05b# awk -F" " -v v1=$RDSK '$0 ~ v1 {print $3,$4,$5,$6,$7}' dumpdates
awk: cmd. line:2: fatal: cannot open file `$0 ~ v1 {print $3,$4,$5,$6,$7}' for reading (No such file or directory)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top