how to trim file - remove the columns with the same value

前端 未结 8 2026
天涯浪人
天涯浪人 2021-01-05 09:15

I would like your help on trimming a file by removing the columns with the same value.

# the file I have (tab-delimited, millions of columns)
jack 1 5 9
joh         


        
8条回答
  •  既然无缘
    2021-01-05 09:48

    As far as I can tell, you'll need to make this a multi-pass program to meet your needs without blowing through memory. For starters, load a single line of the file into an array.

    open FH,'datafile.txt' or die "$!";
    my @mask;
    my @first_line= split(/\s+/,);
    

    Then you'll want to sequentially read in the other lines

    while(my @next_line= split(/\s+/,)) {
    /* compare each member of @first_line to @next_line
     * any match, make a mark in mask to true
     */
    

    When you get to the bottom of the file, go back to the top and use mask to determine which colums to print.

提交回复
热议问题