Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Using awk within system() or open()

by miyagawa (Chaplain)
on Oct 24, 2001 at 12:56 UTC ( [id://121034]=note: print w/replies, xml ) Need Help??


in reply to Using awk within system() or open()

Should be:
open(UPTOP, "cat /proc/uptime | awk '{ print \$1 } |'");

--
Tatsuhiko Miyagawa
miyagawa@cpan.org

Replies are listed 'Best First'.
Re: Re: Using awk within system() or open()
by davorg (Chancellor) on Oct 24, 2001 at 13:01 UTC

    I think I'd write it as:

    open(UPTOP, 'cat /proc/uptime | awk "{ print $1 } |"');
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

      open(UPTOP, 'cat /proc/uptime | awk "{ print $1 } |"');
      Then $1 will be interpolated by shell, won't it? $1 should be AWK variable, neither Perl's one nor shell's one.

      --
      Tatsuhiko Miyagawa
      miyagawa@cpan.org

        D'oh!

        You're right. Try this instead:

        open(UPTOP, q(cat /proc/uptime | awk '{ print $1 } |'));

        Actually, shouldn't it be:

        open(UPTOP, q(cat /proc/uptime | awk '{ print $1 }'|));

        or even (avoiding the "useless use of cat")

        open(UPTOP, q(awk '{ print $1 }' /proc/uptime |));
        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you don't talk about Perl club."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://121034]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-16 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found