This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Field search in BED

Hi. I am an amateur undergraduate computational biologist so please cut me some slack

I have a BED file with five columns, and the fifth column has some field with blank values. So when I intersect it with another file, it shows an error. What command(s) should I write to find and replace the blank values in the fifth column and replace it with something else?

Thanks a lot!

chip-seq unix bed

Hi. I have to modify my question. Whenever I search a blank field, can I write a command to delete that line containing the blank field?

Even if I replace it with 0 or XX, can I delete that line?That was actually the main purpose. I may have thousands of lines that have blank fields and I need to delete them all. Can it be done in one line or first I replace them with 0 or XX and then run some command to delete the line containing that string? If so, what is that 'sed' command? Can i replace 0 with sed in that loop?

Ah so you modified the question then. You do not need to move to 0 for deleting the row. Simple grep that identifies a cell with space removes it. Venu shows the correct one. Please keep your questions targetted as to what you want to do and what you have tried.

1 answer

With awk you can do it. It is just checking for blank spaces and replaceing with 0

awk 'BEGIN { FS = OFS = "\t" } { for(i=1; i<=NF; i++) if($i ~ /^ *$/) $i = 0 }; 1' foo.bed > mod_foo.bed

It is the most widely thing that can be used. It does not matter what replaces. The OP can replace with string as well if its a string column.

Log in to answer this question.