This is a test version of Biostars. For the public version, visit https://www.biostars.org.
BASH Finding Common Elements

Hello!

What is the best way to find common elements between 2 columns using BASH?

bash

Of course, right as I post my answer below, you've edited the question and removed your reproducible example. That information should have been left in your post.

2 answers

Biostars is not a code service - we generally will not provide code for you if you show no effort. In general, you should show what you tried and exactly what issues you're having. Here, you have at least provided a reproducible example, which is good. This is a fairly easy operation via awk (or many other methods) that can easily be found via google. As a warning, questions like this that show no effort may very well be closed in the future, but the following should work for you.

awk 'NR==FNR{c[$1]++;next};c[$1]' DEGs.txt all.genes.txt > output.txt

comm

or diff or sdiff or cmp depending on what you look for

keep anyway in mind that all these linux commands assume you have sorted lists !

Log in to answer this question.