umasuresh has asked for the wisdom of the Perl Monks concerning the following question:

Oh enlightened monks!
I am trying to use a on liner to extract the first three columns of file1 using the following command
perl -pane 'print "$F[0]\t$F[1]\t$F[2]";' file1.txt
But it prints the whole line along with the first 3 columns.
prints: chr1 58963 Gchr1 58963 G G 10 0 10 + 1 ^+. 8 __file1__ chr1 58963 G G 10 0 10 1 ^+. + 8
How do I fix this? Thanks much!

Replies are listed 'Best First'.
Re: using command line autosplit option
by Fletch (Bishop) on Feb 03, 2011 at 19:36 UTC

    The -p and -n flags are mutually exclusive (you want the later in this case). See perlrun.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: using command line autosplit option
by toolic (Bishop) on Feb 03, 2011 at 19:53 UTC
    Another way, with fewer characters, using perl 5.10 (-E and say), -l and array slices:
    perl -lanE'say join"\t",@F[0..2]' file.txt
      Thanks much Toolic and Fletch!