extract multiples columns from txt file perl

后端 未结 3 2086
情歌与酒
情歌与酒 2021-01-17 05:29

I have a txt file like this:

#Genera columnA columnB columnC columnD columnN
x1       1       3       7      0.9      2
x2       5       3       13     7            


        
3条回答
  •  青春惊慌失措
    2021-01-17 06:14

    There are command line switches that are used for this kind of application:

    perl -lnae 'print join "\t", @F[1,3,5]' file.txt
    

    Switch -a automatically creates variable @F for each line, split by whitespace. So @F[1,3,5] is an array slice of elements 1, 3, and 5.

    The downside of this, of course, is that you have to use the column numbers instead of the names.

提交回复
热议问题