http://www.perlmonks.org?node_id=1011790


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.)

    Jim