Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

One-Liner Help

by Anonymous Monk
on Jun 06, 2001 at 18:29 UTC ( [id://86230]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

A collegue has asked me how to write the following command as a one-liner in Perl. I'm not fluent enough with Perl to help her out. Can anyone advise?
cat `lsnrctl stat ZRRI_LISTENER|grep Parameter|awk '{print $4}'`

Replies are listed 'Best First'.
(jptxs)Re: One-Liner Help - WHY?
by jptxs (Curate) on Jun 06, 2001 at 18:40 UTC
    my question: why would you? it's perfectly adequate the way it is. right tool for the right job. that little script is easy to read and understand and appears to function fine.

    do you need it to be cross platform? do you need to incorporate it into a larger all-perl program? these things I could see, but then why ask specifically for a one-liner?

    my only advice is to drop the use of cat; it does nothing =)

    "A man's maturity -- consists in having found again the seriousness one had as a child, at play." --Nietzsche
Re: One-Liner Help
by clintp (Curate) on Jun 06, 2001 at 21:18 UTC
    As a postscript, a shell pet peeve of mine:
    cat `lsnrctl stat ZRRI_LISTENER|grep Parameter|awk '{print $4}'`
    Awk can do the grepping for you:
    cat `lsnrctl stat ZRRI_LISTENER| awk '/Parameter/ {print $4}'`
    Save a process! One day they might be endangered!
(tye)Re: One-Liner Help
by tye (Sage) on Jun 06, 2001 at 20:51 UTC
    lsnrctl stat ZRRI_LISTENER | perl -lane 'print $F[3] if /Parameter/'

    Update: Oops. That isn't the same thing... lsnrctl stat ZRRI_LISTENER | perl -lane 'print $F[3] if /Parameter/' | xargs perl -pe 0 is closer. So, if we wanted to do this without the shell's help: perl -e '@ARGV= map {(split" ")[3]} grep /Parameter/, `lsnrctl stat ZRRI_LISTENER`; print while <>'

            - tye (but my friends call me "Tye")
Re: One-Liner Help
by larryk (Friar) on Jun 06, 2001 at 20:15 UTC
    Well I don't know what lsnrctl stat BLAH does but I'm guessing you're getting some lines of data back. I can't promise this'll work but give it a shot...
    lsnrctl stat ZRRI_LISTENER | perl -e "print map{(split)[4].$/} grep /P +arameter/, <STDIN>"

    "Argument is futile - you will be ignorralated!"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-03-28 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found