Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

using command line autosplit option

by umasuresh (Hermit)
on Feb 03, 2011 at 19:34 UTC ( [id://886049]=perlquestion: print w/replies, xml ) Need Help??

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!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-24 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found