This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to extracting rows that have the same values in all columns in Linux ?

Hi, every one

I have csv file contains many rows, I need extract all rows that have AB value in all columns this sample from my csv file

18125 OAR20_24441405.1 31641310 20 24441405 0.970312 AB AA AB AA AA AB AB AA AA AB AA AA AA AB AA AA AA AA AA AB AA AA AA AA

58012 ilmnseq_rs406679941 45641375 18 46692891 0.9673617 BB AB BB AB BB BB BB BB AB BB BB BB BB BB BB AB AA BB AB AA BB AB BB AA

30159 OAR6_53858058.1 67675371 6 53858058 0.9672967 BB AA BB AA BB AB AB AB AA AB AB AA AB AA AA AB AB BB AB BB AB AA AA BB

24711 OAR3_55534628.1 52677413 3 55534628 0.9671658 BB BB AB BB BB AB BB AA BB AA AB AB AB BB BB AA AB AB BB BB AA AB AA AB

27127 OAR4_85875873.1 33712385 4 85875873 0.9658307 AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB
csv linux awk

2 answers

awk '{for(i=7;i<=NF;i++) if($i!="AB") next; print}' input.txt

damnit :-) just beat me to it .

I had a slightly different approach :

awk '{for(x=6; x<=NF;x++){if($x ~ /AB/){z++}}} END{if (z == NF-6) print }'

EDIT: yours will be bit more efficient, coming to think of it

Thanks for your trial

Dear, can I keep the first row containing the column names ?

Thank you so much

One of the easiest ways

cat your_file.csv | grep "AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB" > my_selected.file

Thank you Antonio for your answer

But I need smart command line with one "AB" that repeated in all columns

Log in to answer this question.