Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter a large file based on a specific column in bash

Tags:

bash

I have a file with >100m lines and wanted to filter it by some criteria:

$ wc -l s1bam.bed 
104797540 s1bam.bed

$ head -n 3 s1bam.bed 
chr1    14688   14979   NB501800:50:H3NW5BGX3:2:22310:19560:5036/1  3   +
chr1    14688   14979   NB501800:50:H3NW5BGX3:3:13501:3458:17919/1  3   +
chr1    14727   15018   NB501800:50:H3NW5BGX3:2:22310:19560:5036/2  3   -

What I wanted to output is the fifth field value >=20 and !=255 (e.g. the second field from right). How to realize it in Bash?

like image 733
David Z Avatar asked Dec 09 '25 11:12

David Z


1 Answers

You can use awk for this:

awk '$5 >= 20 && $5 != 255' file
like image 145
anubhava Avatar answered Dec 11 '25 02:12

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!