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

Re: Grabbing first column of text

by CheeseLord (Deacon)
on Aug 02, 2001 at 20:13 UTC ( [id://101695]=note: print w/replies, xml ) Need Help??


in reply to Grabbing first column of text

Try one of these one-liners (they have the same output, but I thought the second might be a little easier to understand):

perl -ple '($_) = /^\S+/g' filename perl -ple '$_ = (/^\S+/g)[0]' filename

Basically, it reads a line, then sets it to the first group of non-whitespace stuff at the beginning of the line, and then prints the changed line out. Hope this helps!

His Royal Cheeziness

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-23 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found