여러 출력 파일에서 불필요한 데이터를 제거해야 합니다. 각 파일의 일부는 다음과 같습니다.
# BLASTN 2.3.0+
# Query: M03117:99:000000000-ALL7G:1:1101:18697:4431_2:N:0:196
# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db
# 0 hits found
# BLASTN 2.3.0+
# Query: M03117:99:000000000-ALL7G:1:1101:26276:5181_1:N:0:196
# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db
# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end
# 1 hits found
FJ712717_(modified) Trypanosoma brucei brucei from mouse 18S ribosomal RNA gene, partial sequence; internal transcribed spacer 1, complete sequence; and 5.8S ribosomal RNA gene, partial sequence M03117:99:000000000-ALL7G:1:1101:26276:5181_1:N:0:196 FJ712717_(modified) 1.42e-137 1 271 53 323
# BLASTN 2.3.0+
# Query: M03117:99:000000000-ALL7G:1:1101:26276:5181_2:N:0:196
# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db
# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end
# 1 hits found
FJ712717_(modified) Trypanosoma brucei brucei from mouse 18S ribosomal RNA gene, partial sequence; internal transcribed spacer 1, complete sequence; and 5.8S ribosomal RNA gene, partial sequence M03117:99:000000000-ALL7G:1:1101:26276:5181_2:N:0:196 FJ712717_(modified) 1.06e-87 1 197 436 236
# BLASTN 2.3.0+
# Query: M03117:99:000000000-ALL7G:1:1101:10339:5290_1:N:0:196
# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db
# 0 hits found
# BLASTN 2.3.0+
# Query: M03117:99:000000000-ALL7G:1:1101:10339:5290_2:N:0:196
# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db
# 0 hits found
처음 4줄은 하나의 출력 결과를 나타냅니다.
# BLASTN 2.3.0+
# Query: M03117:99:000000000-ALL7G:1:1101:7647:16266_2:N:0:215
# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db
# 0 hits found
조회수가 0인 모든 출력 결과, 즉 4줄을 모두 제거해야 합니다(위에 표시됨).
나는 다음과 같은 결과를 얻었습니다: 1개의 히트가 발견되었으며, 2개의 추가 라인이 추가되었습니다. 6번째 줄은 "#" 기호로 시작하지 않습니다. 어떻게 사용할 수 있나요?
grep -B
이렇게 하라는 명령이요? 내 예상 출력은 "1개의 조회수 발견" 결과만 있는 파일입니다. 아래
# BLASTN 2.3.0+
# Query: M03117:99:000000000-ALL7G:1:1101:26276:5181_1:N:0:196
# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db
# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end
# 1 hits found
FJ712717_(modified) Trypanosoma brucei brucei from mouse 18S ribosomal RNA gene, partial sequence; internal transcribed spacer 1, complete sequence; and 5.8S ribosomal RNA gene, partial sequence M03117:99:000000000-ALL7G:1:1101:26276:5181_1:N:0:196 FJ712717_(modified) 1.42e-137 1 271 53 323
# BLASTN 2.3.0+
# Query: M03117:99:000000000-ALL7G:1:1101:26276:5181_2:N:0:196
# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db
# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end
# 1 hits found
FJ712717_(modified) Trypanosoma brucei brucei from mouse 18S ribosomal RNA gene, partial sequence; internal transcribed spacer 1, complete sequence; and 5.8S ribosomal RNA gene, partial sequence M03117:99:000000000-ALL7G:1:1101:26276:5181_2:N:0:196 FJ712717_(modified) 1.06e-87 1 197 436 236
# BLASTN 2.3.0+
# Query: M03117:99:000000000-ALL7G:1:1101:11481:5777_1:N:0:196
# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db
# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end
# 1 hits found
JN673389_(modified) Trypanosoma congolense isolate TS07210 18S ribosomal RNA gene, partial sequence; internal transcribed spacer 1, 5.8S ribosomal RNA gene, and internal transcribed spacer 2, complete sequence; and 28S ribosomal RNA gene, partial sequence M03117:99:000000000-ALL7G:1:1101:11481:5777_1:N:0:196 JN673389_(modified) 2.04e-105 1 231 23 253
# BLASTN 2.3.0+
# Query: M03117:99:000000000-ALL7G:1:1101:11481:5777_2:N:0:196
# Database: /home/alex/blast/db/tryps_ITS/tryps_ITS_db
# Fields: subject title, query acc., subject acc., evalue, q. start, q. end, s. start, s. end
# 1 hits found
TCU22315_(modified) Trypanosoma congolense IL1180 18S, 5.8S, 28S-LS1, srRNA1, complete sequence, and 28S-LS2 ribosomal RNA, partial sequence M03117:99:000000000-ALL7G:1:1101:11481:5777_2:N:0:196 TCU22315_(modified) 1.40e-75 1 156 1176 1021
답변1
다음과 같이 를 tac
사용하여 파일의 줄을 뒤집고 일치하는 패턴이 포함된 줄을 포함하여 패턴을 일치시키기 전에 3줄을 삭제할 수 있습니다.sed
tac filename | sed '/0 hits/I,+3 d' | tac
파일을 그 자리에서 편집하려면 다음과 같은 명령 -i
에서 옵션을 사용할 수 있습니다 sed
.
tac filename | sed -i '/0 hits/I,+3 d' filename | tac