Urgent:awk variable question 
Author Message
 Urgent:awk variable question

Can anyone shed light on an awk question?

 How can one "represent" a variable ($count) within an awk
 statement? the one below doesn't seem to work. tried the \,
 quotes, nothing worked.

         result=`server_df $svr | awk 'NR==$count{print
 $1,"|",$2,"|",$3,"|",$4,"|
 ",$5,"|",$6}'`

Many Thanks

Che



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question
Can anyone shed light on an awk question?

 How can one "represent" a variable ($count) within an awk
 statement? the one below doesn't seem to work. tried the \,
 quotes, nothing worked.

         result=`server_df $svr | awk 'NR==$count{print
 $1,"|",$2,"|",$3,"|",$4,"|
 ",$5,"|",$6}'`

Many Thanks

Che



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question
Can anyone shed light on an awk question?

 How can one "represent" a variable ($count) within an awk
 statement? the one below doesn't seem to work. tried the \,
 quotes, nothing worked.

         result=`server_df $svr | awk 'NR==$count{print
 $1,"|",$2,"|",$3,"|",$4,"|
 ",$5,"|",$6}'`

Many Thanks

Che



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question
Can anyone shed light on an awk question?

 How can one "represent" a variable ($count) within an awk
 statement? the one below doesn't seem to work. tried the \,
 quotes, nothing worked.

         result=`server_df $svr | awk 'NR==$count{print
 $1,"|",$2,"|",$3,"|",$4,"|
 ",$5,"|",$6}'`

Many Thanks

Che



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question
Can anyone shed light on an awk question?

 How can one "represent" a variable ($count) within an awk
 statement? the one below doesn't seem to work. tried the \,
 quotes, nothing worked.

         result=`server_df $svr | awk 'NR==$count{print
 $1,"|",$2,"|",$3,"|",$4,"|
 ",$5,"|",$6}'`

Many Thanks

Che



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question
Can anyone shed light on an awk question?

 How can one "represent" a variable ($count) within an awk
 statement? the one below doesn't seem to work. tried the \,
 quotes, nothing worked.

         result=`server_df $svr | awk 'NR==$count{print
 $1,"|",$2,"|",$3,"|",$4,"|
 ",$5,"|",$6}'`

Many Thanks

Che



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question
Can anyone shed light on an awk question?

 How can one "represent" a variable ($count) within an awk
 statement? the one below doesn't seem to work. tried the \,
 quotes, nothing worked.

         result=`server_df $svr | awk 'NR==$count{print
 $1,"|",$2,"|",$3,"|",$4,"|
 ",$5,"|",$6}'`

Many Thanks

Che



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question
Can anyone shed light on an awk question?

 How can one "represent" a variable ($count) within an awk
 statement? the one below doesn't seem to work. tried the \,
 quotes, nothing worked.

         result=`server_df $svr | awk 'NR==$count{print
 $1,"|",$2,"|",$3,"|",$4,"|
 ",$5,"|",$6}'`

Many Thanks

Che



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question
Can anyone shed light on an awk question?

 How can one "represent" a variable ($count) within an awk
 statement? the one below doesn't seem to work. tried the \,
 quotes, nothing worked.

         result=`server_df $svr | awk 'NR==$count{print
 $1,"|",$2,"|",$3,"|",$4,"|
 ",$5,"|",$6}'`

Many Thanks

Che



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question
Can anyone shed light on an awk question?

 How can one "represent" a variable ($count) within an awk
 statement? the one below doesn't seem to work. tried the \,
 quotes, nothing worked.

         result=`server_df $svr | awk 'NR==$count{print
 $1,"|",$2,"|",$3,"|",$4,"|
 ",$5,"|",$6}'`

Many Thanks

Che



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question

Quote:

>Can anyone shed light on an awk question?

> How can one "represent" a variable ($count) within an awk
> statement? the one below doesn't seem to work. tried the \,
> quotes, nothing worked.

>         result=`server_df $svr | awk 'NR==$count{print
> $1,"|",$2,"|",$3,"|",$4,"|
> ",$5,"|",$6}'`

>Many Thanks

>Che

This is essentially a shell quoting question/solution:

 result=`server_df $svr | awk 'NR=='"$count"'{print
 $1,"|",$2,"|",$3,"|",$4,"|",$5,"|",$6}'`

 There are other ways, but you asked too many times for me to bother
 telling you.  Look in the FAQ.

 Chuck Demas
 Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question

Quote:

>This is essentially a shell quoting question/solution:

> result=`server_df $svr | awk 'NR=='"$count"'{print
> $1,"|",$2,"|",$3,"|",$4,"|",$5,"|",$6}'`

> There are other ways, but you asked too many times for me to bother
> telling you.  Look in the FAQ.

It isn't every day that you see someone making something a(n) FAQ all by
himself - and all in one day...


Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question

Quote:

> Can anyone shed light on an awk question?

>  How can one "represent" a variable ($count) within an awk
>  statement? the one below doesn't seem to work. tried the \,
>  quotes, nothing worked.

Your $count is inside the 'single quotes' for the shell, so the shell
doesn't expand your $count.

Instead of

Quote:
>          result=`server_df $svr | awk 'NR==$count{print
>  $1,"|",$2,"|",$3,"|",$4,"|
>  ",$5,"|",$6}'`

try
           result=`server_df $svr | awk 'NR=='$count'{print
   $1,"|",$2,"|",$3,"|",$4,"|
   ",$5,"|",$6}'`
or
           result=`server_df $svr | awk 'NR=='"$count"'{print
   $1,"|",$2,"|",$3,"|",$4,"|
   ",$5,"|",$6}'`
or
           result=`server_df $svr | awk -v count=$count 'NR==count{print
   $1,"|",$2,"|",$3,"|",$4,"|
   ",$5,"|",$6}'`
or
           result=`server_df $svr | awk 'NR==ENVIRON["count"]{print
   $1,"|",$2,"|",$3,"|",$4,"|
   ",$5,"|",$6}'`

Regards...
                Michael



Sun, 18 Aug 2002 03:00:00 GMT  
 Urgent:awk variable question

% Can anyone shed light on an awk question?

Yes, but this isn't really an awk question.

%  How can one "represent" a variable ($count) within an awk

One way is to assign your shell variable to an awk variable:

  result=`server_df $svr | awk -v count=$count -v OFS="|" 'NR==count {
       print $1, $2, $3, $4, $5, $6 }'`

Another way is to{*filter*}around with quoting. Read your shell man page
for details:

  result=`server_df $svr | awk -v OFS="|" "NR==$count"' {
       print $1, $2, $3, $4, $5, $6 }'`
or
  result=`server_df $svr | awk -v OFS="|" 'NR=='$count' {
       print $1, $2, $3, $4, $5, $6 }'`
or
  result=`server_df $svr | awk -v OFS="|" "NR==$count {
       print \$1, \$2, \$3, \$4, \$5, \$6 }"`

--

Patrick TJ McPhee
East York  Canada



Mon, 19 Aug 2002 03:00:00 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. awk variables --> shell variables

2. URGENT URGENT URGENT

3. URGENT: Need help with AND binary operation in awk

4. AWK sort assistance!Urgent please..

5. Urgent awk print assistance please!

6. Need Help on awk!!!! **** Urgent ****

7. How do I display the contents of a shell variable from an awk script via a awk variable

8. $_GET variable variables, dynamic parsing (I'm not sure how to summarize this question)

9. Newbie question: Logical variable in CLP/Prolog vs variable in C

10. TCL Newbie Question: using variables to reference variables

11. variabe in variable like in ksh in awk?

12. AWK-Script to set a shell variable (Win32) ?

 

 
Powered by phpBB® Forum Software