This is a test version of Biostars. For the public version, visit https://www.biostars.org.
awk command for printing all the repeated matching lines without making them unique

I have two files file1 file2 which has taxonomy details .

for example

file1 : ( it has taxonomy ID - some digit)

9

9

4

4

4

file2 : ( it has other taxonomy details along with taxonomy ID )

9 A B C D

4 P Q R S

I want to get an output like output :

9 A B C D

9 A B C D

4 P Q R S

4 P Q R S

4 P Q R S

I tried using this command

awk -F '\t' 'NR==FNR{a[$1];next} ($1) in a' file1 file2

awk

I have two taxonomy data files , I am trying to map them with their taxID . and want to get all the repeated matched taxIDs along with other details.

$ cat test1.txt | xargs -i sed -n '/{}/p' test2.txt

9   A B C D
9   A B C D
4   P Q R S
4   P Q R S
4   P Q R S

$ parallel sed -n /{}/p test2.txt :::: test1.txt 
9   A B C D
9   A B C D
4   P Q R S
4   P Q R S
4   P Q R S

2 answers

You don't need awk for this.

Following the data you shared here, just sort file1 and file2, and use join like so:

$ join -1 1 -2 1 <(sort file1) <(sort file2)
4 P Q R S
4 P Q R S
4 P Q R S
9 A B C D
9 A B C D
join -t $'\t' -1 1 -2 1 <(sort -t $'\t' -k1,1 file1) <(sort -t $'\t' -k1,1 file2)

Log in to answer this question.