Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Simple awk question

by no_slogan (Deacon)
on Jun 05, 2014 at 17:05 UTC ( [id://1088882]=note: print w/replies, xml ) Need Help??


in reply to Simple awk question

Perl has awk functionality built in, so you can do something like:

$x = "ack thpt barf"; @fields = split " ", $x; print $fields[0], "\n";

Replies are listed 'Best First'.
Re^2: Simple awk question
by czah7 (Initiate) on Jun 05, 2014 at 18:39 UTC
    I think this is exactly what I need! Thanks.

      On second thought. Almost! I need $fields to now be just that first field. Not just print the first field, it now needs to be a new variable.

      I tried
      $fields = print $fields[0], "\n";
      close but no cigar, yet.

        Don't assign the return of print, just assign the value of the index array element:

        my $field = $fields[0]; print "$field\n";

        But why not just use Perl's awk mode instead?

        echo '2014-06-04T15:24:21-05:00 syslog_dp [0x80e00099][ftp][error] sec +ure-backup(FBB): trans(5487)' | perl -lape '$_=$F[0]'

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)
        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-03-28 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found