![根据第一列将多列拆分为两列](https://linux22.com/image/136384/%E6%A0%B9%E6%8D%AE%E7%AC%AC%E4%B8%80%E5%88%97%E5%B0%86%E5%A4%9A%E5%88%97%E6%8B%86%E5%88%86%E4%B8%BA%E4%B8%A4%E5%88%97.png)
我有一个大的制表符分隔文件,如下所示
ENSBTAP00000053998 GO:0005576 GO:0006952
ENSBTAP00000014280 GO:0005515
XP_010996658.1 GO:0005515 GO:0032947
ENSCAFP00000005761-D107 GO:0006826 GO:0006879 GO:0008199
XP_010987712.1-D2 GO:0004579 GO:0008250 GO:0016021
ENSBTAP00000018349-D5 GO:0003677 GO:0003700 GO:0005634 GO:0006355 GO:0043565
我怎样才能将上表转换为如下所示
ENSBTAP00000053998 GO:0005576
ENSBTAP00000053998 GO:0006952
ENSBTAP00000014280 GO:0005515
XP_010996658.1 GO:0005515
XP_010996658.1 GO:0032947
ENSCAFP00000005761-D107 GO:0006826
ENSCAFP00000005761-D107 GO:0006879
ENSCAFP00000005761-D107 GO:0008199
XP_010987712.1-D2 GO:0004579
XP_010987712.1-D2 GO:0008250
XP_010987712.1-D2 GO:0016021
ENSBTAP00000018349-D5 GO:0003677
ENSBTAP00000018349-D5 GO:0003700
ENSBTAP00000018349-D5 GO:0005634
ENSBTAP00000018349-D5 GO:0006355
ENSBTAP00000018349-D5 GO:0043565
答案1
使用 awk:
awk '{for(i=2;i<=NF;i++) print $1,$i}' OFS='\t' file
或 Perl
perl -alne '$x = shift @F; print "$x\t$_" for @F' file