我有一个像这样的条目的文件:
@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行。所以我使用了以下命令:
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
答案 0 :(得分:3)
如果您只想剪切每一条线,保持其他线不变,则可能更容易使用awk
:
awk 'NR % 2 == 0 { print substr($0, 0, 45) } NR % 2 == 1 { print }' BT8_A.fastq
答案 1 :(得分:3)
一种方式:
$ sed 'n;s/\(.\{45\}\).*/\1/' file
答案 2 :(得分:2)
这是一个sed one-liner:
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