Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: perl one liner print columns 2.. last

by Anonymous Monk
on Jan 05, 2013 at 14:22 UTC ( #1011790=note: print w/replies, xml ) Need Help??

in reply to perl one liner print columns 2.. last

Thanks for all the timely and helpful replies! Even answers not actually solving the problem, are very educational. I should have provided more detail, this problem has stymied me many times in many situations, and I finally got frustrated enough to ask the question. (and got the answer(s)!) In this case I wanted to print history without the line numbers on lines that were whitespace separated and variable columns. Thanks to all again! These worked for me ...

history|perl -lane 'print join q{ }, @F[1..$#F]' perl -lane 'print join q{ }, @F[1..$#F]' /tmp/1.out

Replies are listed 'Best First'.
Re^2: perl one liner print columns 2.. last
by Jim (Curate) on Jan 06, 2013 at 17:14 UTC

    If you have both history and Perl, then you probably also have cut.

    history | cut -f 2-

    On my system, -n suppresses line numbers (but not the leading tab).

    history -n

    Though it's handy to know -a and @F autosplit command-line idioms for use in some situations, this specific situation is one for which there's a simpler, less arcane way that doesn't require Perl. Also, using cut is less destructive than using Perl because it doesn't convert tabs to spaces as the Perl autosplit trick does. (Of course, this can be remedied by specifying an alternate separator pattern with the -F command-line option, but this is just leading you down the garden path.)


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-11-13 01:15 GMT
Find Nodes?
    Voting Booth?
    My code is most likely broken because:

    Results (146 votes). Check out past polls.