0

i have two files, file1 have a column with ~600 row and file2 have ~20 columns and ~3000 row. i want to find patterns form file1 that are common in file2.

file1:

K00001 K00002 K00003 K00006 K00013 K00025 K00089 

file2:

TRINITY_DN102283_c0_g1 KEGG:xtr:496432`KO:K16860 TRINITY_DN42420_c0_g1 KO:K01762 TRINITY_DN52581_c0_g1 KEGG:zma:732844`KO:K13523 TRINITY_DN36387_c0_g2 KEGG:zma:732811`KO:K00089 TRINITY_DN54650_c4_g1 KEGG:zma:542598`KO:K00025 TRINITY_DN93494_c0_g1 KEGG:zma:542598`KO:K00025 TRINITY_DN36051_c0_g1 KEGG:zma:542598`KO:K00025 

i would like obtain a result like this:

K00025 K00089 
1
  • yes i want ti find common words Commented May 5, 2016 at 18:29

2 Answers 2

2
comm -12 <(grep -oP '\w+' a|sort -u) <(grep -oP '\w+' b|sort -u) 

where:

  • grep -oP '\w+' a|sort -u gets a sorted list o words in file a
  • the some for file b
  • comm -12 outputs common lines
0

You can do this with the following snippet

grep -f file1 -o file2 | sort -u K00025 K00089 
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.