How to print the header of bed file and the lines that belong to chromosome 2
2
0
Entering edit mode
3.5 years ago
FadyNabil ▴ 20

I have a bed file consists of many lines and I want to extract the header and the lines that belong to chromosome 2 only in another file

fastq Bed_files fasta Bash • 1.6k views
ADD COMMENT
1
Entering edit mode
3.5 years ago
FadyNabil ▴ 20
awk 'NR == 1 || ($1=="chr2")' lamina.bed 
ADD COMMENT
0
Entering edit mode
3.5 years ago

If the BED file is sorted, here's a faster way:

$ cat <(head -1 regions.bed) <(bedextract chr2 regions.bed) > answer.bed

Generically, using awk to solve this will require reading through the entire file. This can be expensive for whole-genome scale files.

ADD COMMENT

Login before adding your answer.

Traffic: 2382 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6