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!

printing fields using parameters

Status
Not open for further replies.

kasparov

Programmer
Feb 13, 2002
203
GB
Can someone tell me how I can use a variable as the parameter to a print startement? e.g.

VAR=7
echo $LINE | awk '{ print ??? }'

I want to print the 7th field in $LINE (but next time $VAR will have a different value). I've tried all the variations of dollar signs & brackets that I can think of but I either get the whole of $LINE or a syntax error.

TIA, Chris
 
VAR=7
echo $LINE | awk -v field="${VAR}" '{ print $field }' vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Vlad

Thanks for the reply - unfortunately I'm still getting a syntax error:

awk: syntax error near line 1
awk: bailing out near line 1

I'm on Solaris 8 using ksh if that's any use?

Chris
 
use nawk instead of awk vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top