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

Re: Simple awk question

by Bloodnok (Vicar)
on Jun 05, 2014 at 17:26 UTC ( #1088884=note: print w/replies, xml ) Need Help??


in reply to Simple awk question

How about echo $variable | perl -nae 'print $a[0]' or possibly perl -e 'print((split /\s+/, "'$variable'")[0])' ?

Update:

Very many thanx to LanX - modifed 2nd suggestion to correct parenthesis, but ignored nested quotes comment since they are most definitely deliberate - without them, perl would split the string '$variable' whereas with them, the shell expands the shell variable and perl then splits that string.

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Simple awk question
by LanX (Archbishop) on Jun 05, 2014 at 18:03 UTC
    perl -e 'print (split /\s+/, "'$variable'")[0]'

    nested quotes? :)

    update

    and the brackets belong to print , (...)[0] won't work.

    Cheers Rolf

    (addicted to the Perl Programming Language)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2020-06-02 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (19 votes). Check out past polls.

    Notices?