osx - Create a new file based on matching between two files -


i having 2 files

first file in format. each line starts unique id (in case p22465)

p22465    db   db; ec.31.1.1; annexin (annexin) group. 

second file in format.each line starts (some number)@entrezgene

309@entrezgene|anxa6_human@swissprot|p08133@swissprot|anxa6:anxa6|67 kda calelectrin  30@entrezgene|thik_human@swissprot|p22465@swissprot|acaa1:acaa1|ec 2.3.1.16 

output should

30@entrezgene|thik_human@swissprot|p22465@swissprot|acaa1:acaa1|ec 2.3.1.16 

it should match line containing unique id (p22465) in second file , copy whole line new file

using bash:

fgrep -f <(awk '{print $1}' file1) file2 

this uses process substitution (<(...)). with:

awk '{print $1}' file1 | fgrep -f - file2 

this tells fgrep 'read strings matched standard input' (-f -). i've not verified works, i'd expect so.

you can use grep -f in lieu of fgrep (but mac os x has fgrep).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -