in reply to Loop, but print once.
This should get you started:
$ perl -e' $x = <<STUFF; 1\t300\t1_a\t30\t1_b\t20 1\t300\t2_a\t22\t2_b\t12 1\t320\t1_a\t10\t1_b\t30 1\t320\t2_a\t32\t2_b\t22 2\t312\t1_a\t30\t1_b\t20 2\t312\t2_a\t22\t2_b\t12 2\t310\t1_a\t31\t1_b\t20 2\t310\t2_a\t21\t2_b\t12 STUFF open my $fh, "<", \$x or die $!; my @last; while ( <$fh> ) { my @fields = split /\t/; for my $i ( 0 .. $#fields ) { if ( $fields[ $i ] eq $last[ $i ] ) { $fields[ $i ] = ""; } else { last; } } print join "\t", @fields; @last = split /\t/; } ' 1 300 1_a 30 1_b 20 2_a 22 2_b 12 320 1_a 10 1_b 30 2_a 32 2_b 22 2 312 1_a 30 1_b 20 2_a 22 2_b 12 310 1_a 31 1_b 20 2_a 21 2_b 12
|
|---|