Simple awk command within a perl script 
Author Message
 Simple awk command within a perl script

My goal is to print out all interfaces that contain the string "ppp" from
the routing table.

When run from the command line, this works perfectly:

% route | awk '/ppp/ { print $8 }' | sort -u
ppp6

But the following lines within my perl script:



produce the entire line output(IPs for example only):


192.100.10.200  *               255.255.255.255 UH    0      0        0 ppp6
default         192.100.10.200  0.0.0.0         UG    0      0        0 ppp6


should contain a list of the interfaces only. For example, if there were

instance, the perl program should simply print out "ppp6".

What am I doing incorrectly? Thanks for any suggestions!

--
Tom Funk



Sat, 27 Jul 2002 03:00:00 GMT  
 Simple awk command within a perl script



why are you calling awk and sort from WITHIN perl? perl can do both and
save you plenty of trouble.

  TF> produce the entire line output(IPs for example only):


  TF> 192.100.10.200  *               255.255.255.255 UH    0      0        0 ppp6
  TF> default         192.100.10.200  0.0.0.0         UG    0      0        0 ppp6

this does it in pure perl:

perl -ane '$u{ $F[-1] } = 1 ; END{ print "$_\n" for sort keys %u }' file....


  TF> should contain a list of the interfaces only. For example, if there were

  TF> instance, the perl program should simply print out "ppp6".

backticks in perl are double quotish so the $8 is getting interpolated
(with a null string value most likely) and awk never sees it. backwhack
the $ to fix that.

uri

--

SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com



Sat, 27 Jul 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. shell commands within awk script

2. Access to Script Name Within Awk Script

3. Run a Perl script within TCL

4. Replacing a string from an input file within awk script

5. trying to call awk from within a shell script

6. problem with awk in perl script

7. Run awk from within sed script?

8. using Oracle within an awk script

9. awk within ksh script

10. Running Awk scripts from within VB

11. Shell variable within an awk script

12. How to specify input file within awk script?

 

 
Powered by phpBB® Forum Software