提取每一行并将其附加到其中一列的另一个文件中

时间:2019-03-27 03:38:34

标签: awk

如何从下面的文件中提取每一行并将内容附加到以第三列命名的文件(例如Backbone_3710)中?

HWI-ST945_0069:2:1101:17889:2254#GNNNNN/11      16      Backbone_3710   13730   1       28M1D61M1D11M   *       0       0       AATAGGGAAAAGCCGGCTATCGGAATCGAACCGATGACCATCGCATTACAAATGCGATGCTCTAACCTCTGAGCTAAGCGGGCCCACATAACAGAAATCT    *       NM:i:5  ms:i:144        AS:i:148        nn:i:0  tp:A:P  cm:i:5  s1:i:40 s2:i:59 de:f:0.0490     rl:i:0
HWI-ST945_0069:2:1101:17753:2257#GNNNNN/11      16      Backbone_2546   1217877 23      23S62M1I14M     *       0       0       ATTTGATTGTGCATATTAGTGTGTTTTTTCATTTGTGCATGCATGGCAAGTCATAAAAAATACAAAAGAACTACATAAGCATTTAGGGTTTAATTTCACA    *       NM:i:3  ms:i:118        AS:i:118        nn:i:0  tp:A:P  cm:i:3  s1:i:51 s2:i:0  de:f:0.0390     rl:i:0
HWI-ST945_0069:2:1101:17922:2282#ANNNNN/11      16      Backbone_2065   955626  2       16S20M2I7M1D11M3I35M1D6M        *       0       0       GAACGAGAAGAAGATTATTTCAACGTCGAGGCTTGGAAAAACTTTATTTAGGAGCTTCAAATTGATAGGGCAGTCCTACGAGTGGAATAAGAGGACATGT    *       NM:i:9  ms:i:78 AS:i:80 nn:i:0  tp:A:P  cm:i:4  s1:i:27 s2:i:0  de:f:0.0723     rl:i:0
HWI-ST945_0069:2:1101:17799:2282#ANNNNN/11      16      Backbone_3859   11630   1       75M1I24M        *       0       0       TCGTGTTCAACACAGTATTCATACGGGAAATTATGATCAAAGAGTTCTTTATCAACCGCCATCTACTTCAGAGATCCCTACGGAAATCTTTTTCAAATAC    *       NM:i:5  ms:i:144        AS:i:144        nn:i:0  tp:A:P  cm:i:5  s1:i:47 s2:i:54 de:f:0.0500     rl:i:0
HWI-ST945_0069:2:1101:17876:2290#GNNNNN/11      0       Backbone_1630   114655  2       23S37M40S       *       0       0       ACATGCATAAGGAATCTTTGGCCTAGTCTCAAAAGTCGGTCTAATTCAGAAGTACTAATTCAAGAGATAGAATATGAGGATGAACAAGAGTATGATAAGG    *       NM:i:1  ms:i:64 AS:i:64 nn:i:0  tp:A:P  cm:i:3  s1:i:27 s2:i:0  de:f:0.0270     rl:i:0
HWI-ST945_0069:2:1101:17982:2293#GNNNNN/11      4       *       0       0       *       *       0       0       TGATTAAAATAATTGCTCATAAATATAATAGAATTAAAGGAAAAAGGTAAAAGAAAGCATTGAAGAAAAGAAAGAAAGAGCCAAGTTTTATATGCAGTAG    *       rl:i:0
HWI-ST945_0069:2:1101:17833:2296#GNNNNN/11      4       *       0       0       *       *       0       0       TGAGGGTTCCAGATTAAATGCCAATTCAAACTTCCTACTGGGAATCATTGTTCAGGCGAGTTCTGACAACTCTTAGTGGAGAAGGCATTGGTGCCTACCC    *       rl:i:0
HWI-ST945_0069:2:1101:17908:2302#GNNNNN/11      4       *       0       0       *       *       0       0       TAATTTAAATAGTGCATTGGACTTTCAGATTTGGTTCAATATTCAACATGGGTCGACTTCTTATGGATGATTTTAGAAGTGGGTTTGAGGAAGGACCTTG    *       rl:i:0
HWI-ST945_0069:2:1101:17759:2305#ANNNNN/11      16      Backbone_870    367318  10      27M1I34M3D6M1I31M       *       0       0       ACATAGGGCCTCCATTCCCTAGTCGCCTTTTTGGAACATTAGGGCTCCAATCCCAGAGTTGAGTTTAATAGATAGGGCCTCCATTCCCTAGTCGCCTTTT    *       NM:i:13 ms:i:78 AS:i:78 nn:i:0  tp:A:P  cm:i:3  s1:i:43 s2:i:42 de:f:0.1089     rl:i:0
HWI-ST945_0069:2:1101:17878:2318#GNNNNN/11      0       Backbone_2304   815440  1       67M1D27M6S      *       0       0       TGGGTTCTTTTATTAAAGACCCTATATGCTTTACTACGTGAGGAATATCCAATGAAAATACCTTCATCCGACTTAGCATCAAATTTACCCAATTAGTCTT    *       NM:i:3  ms:i:160        AS:i:160        nn:i:0  tp:A:P  cm:i:7  s1:i:60 s2:i:71 de:f:0.0316     rl:i:0

谢谢。

1 个答案:

答案 0 :(得分:1)

类似

awk '$3 != "*" { print $0 >> $3; close($3) }' input.txt

应该工作。请注意,在每次打印后都要使用close(),以免在会有大量不同的输出文件的情况下用完文件描述符。