1

我有一个像这样的条目的文件:

@HWI-ST750:151:C1C6AACXX:8:1101:10000:14114/1
AAACATACCATTGCATATTTCGTATAATTCGAATTTAAGCAAGTTGTATTGCCAACAGCTCAGATCAATTAAGAATCTTTTCAAATTTATCAATTTA
+/1
DDHBFHHIAHHJEGJFGICHG;CGHGIJIIAIHHIJIGAGIE9FDFHGHG:4???BBC@8=;@FHI:DACHE>>AEAA@;B@;)6(>AC@>35@DDC
@HWI-ST750:151:C1C6AACXX:8:1101:10000:37802/1
GTTCCTTTACTTGCTCCCATGTCCCAATCTAACACACATGAGTCGTCGCACGCCAGTAAATCTAAAGATTTCAGACACTCAGACTCGTACAGTGAAA
+/1
FHHHHHJJIJJJJJJJJJJJJIJJJIJJJJJJJJJJJIHJIJ@GIHIIJJJIJHGHFFFFFFEEDEEEEDDDDDDDDDCDDCCCDDDABBDD>CC>A

我想从第 1 个字到第 45 个字的每 2 行删减一次。所以我使用了以下命令:

sed "0~2p" BT8_A.fastq | cut -c1-45 | head -n 12

它工作正常,但在切割第 45 个单词后,同一行被附加到下一行。像这样 -

@HWI-ST750:151:C1C6AACXX:8:1101:10000:14114/1
AAACATACCATTGCATATTTCGTATAATTCGAATTTAAGCAAGTT
AAACATACCATTGCATATTTCGTATAATTCGAATTTAAGCAAGTT
+/1
DDHBFHHIAHHJEGJFGICHG;CGHGIJIIAIHHIJIGAGIE9FD
DDHBFHHIAHHJEGJFGICHG;CGHGIJIIAIHHIJIGAGIE9FD
@HWI-ST750:151:C1C6AACXX:8:1101:10000:37802/1
GTTCCTTTACTTGCTCCCATGTCCCAATCTAACACACATGAGTCG
GTTCCTTTACTTGCTCCCATGTCCCAATCTAACACACATGAGTCG
+/1
FHHHHHJJIJJJJJJJJJJJJIJJJIJJJJJJJJJJJIHJIJ@GI
FHHHHHJJIJJJJJJJJJJJJIJJJIJJJJJJJJJJJIHJIJ@GI

我无法解决这个问题。我在这里哪里出错了。帮我。

谢谢你。

我想要的输出是:

@HWI-ST750:151:C1C6AACXX:8:1101:10000:14114/1
AAACATACCATTGCATATTTCGTATAATTCGAATTTAAGCAAGTT
+/1
DDHBFHHIAHHJEGJFGICHG;CGHGIJIIAIHHIJIGAGIE9FD
@HWI-ST750:151:C1C6AACXX:8:1101:10000:37802/1
GTTCCTTTACTTGCTCCCATGTCCCAATCTAACACACATGAGTCG
+/1
FHHHHHJJIJJJJJJJJJJJJIJJJIJJJJJJJJJJJIHJIJ@GI
4

3 回答 3

3

如果您只想剪切每 2 行,而其他行保持不变,则使用起来可能更容易awk

awk 'NR % 2 == 0 { print substr($0, 0, 45) } NR % 2 == 1 { print }' BT8_A.fastq
于 2013-02-20T10:14:37.813 回答
3

单程:

$ sed 'n;s/\(.\{45\}\).*/\1/' file
于 2013-02-20T10:19:01.490 回答
2

这是一个 sed 单线:

sed -r '2~2s/^(.{45}).*/\1/' file  

输出:

kent$  sed -r '2~2s/^(.{45}).*/\1/' file                                            │drwxr-xr-x 4 kent kent  160 Feb 15 16:48 pkg/
@HWI-ST750:151:C1C6AACXX:8:1101:10000:14114/1                                         │-rw-r--r-- 1 kent kent   19 Feb 15 14:06 status.xml
AAACATACCATTGCATATTTCGTATAATTCGAATTTAAGCAAGTT                                         │-rw-r--r-- 1 kent kent  18K Feb 15 16:44 tinyswitch.tgz
+/1                                                                                   │-rw-r--r-- 1 kent kent   73 Feb 15 14:06 t.sh
DDHBFHHIAHHJEGJFGICHG;CGHGIJIIAIHHIJIGAGIE9FD                                         │-rw-r--r-- 1 kent kent  18K Feb 15 16:24 tsw.tgz
@HWI-ST750:151:C1C6AACXX:8:1101:10000:37802/1                                         │-rw-r--r-- 1 kent kent 7.5K Feb 19 18:44 vimod.zsh
GTTCCTTTACTTGCTCCCATGTCCCAATCTAACACACATGAGTCG                                         │-rw-r--r-- 1 kent kent  23K Feb 19 22:09 vimrd
+/1                                                                                   │-rw-r--r-- 1 kent kent   42 Feb 17 16:00 x.txt
FHHHHHJJIJJJJJJJJJJJJIJJJIJJJJJJJJJJJIHJIJ@GI
于 2013-02-20T10:23:58.267 回答