linux - Bash - Check if line in one file exists in another file -


i wanted know how can check if 1 line first column exists part of line in file. instance if have following files:

a.txt:

0000_01_000000049e 7821069312 0000_01_000000049f 7886800896 0000_01_00000004a1 8302987264 0000_01_00000004a2 8469055488 0000_01_00000004a3 8040450048 0000_01_00000004a5 8250165248 0000_01_00000004a6 8116242432 0000_01_00000004a7 8260126720 0000_01_00000004a9 6420892672 0000_01_00000004aa 1076364288 0000_01_00000004ab 7822870528 0000_01_00000004ae 4297589760 0000_01_00000004af 2360320 

b.txt:

0000_01_000000049e,000000,0000_02_00000002aa,7821070336,1451596986,l3,0,0 0000_01_000000049f,000001,0000_02_00000002aa,7886801920,1451623534,l3,0,0 0000_01_00000004a0,000002,0000_02_00000002aa,6888983552,1451051126,l3,0,0 0000_01_00000004a1,000003,0000_02_00000002aa,8302988288,1451618939,l3,0,0 0000_01_00000004a2,000004,0000_02_00000002aa,8469056512,1451605811,l3,0,0 0000_01_00000004a3,000005,0000_02_00000002aa,8040451072,1452180174,l3,0,0 0000_01_00000004a4,000006,0000_02_00000002aa,8569819136,1451541232,l3,0,0 0000_01_00000004a5,000007,0000_02_00000002aa,8250166272,1452181606,l3,0,0 0000_01_00000004a6,000008,0000_02_00000002aa,8116243456,1452013786,l3,0,0 0000_01_00000004a7,000009,0000_02_00000002aa,8260127744,1451420337,l3,0,0 0000_01_00000004a8,000010,0000_02_00000002aa,8454605824,1451542793,l3,0,0 0000_01_00000004a9,000011,0000_02_00000002aa,7543657472,1451568105,l3,0,0 0000_01_00000004aa,000012,0000_02_00000002aa,7654181888,1451494089,l3,0,0 0000_01_00000004ab,000013,0000_02_00000002aa,7822871552,1451590252,l3,0,0 0000_01_00000004ac,000014,0000_02_00000002aa,5295639552,1450925203,l3,0,0 0000_01_00000004ad,000015,0000_02_00000002aa,7793807360,1451470796,l3,0,0 0000_01_00000004ae,000016,0000_02_00000002aa,8330842112,1451591997,l3,0,0 0000_01_00000004af,000017,0000_02_00000002aa,29039368192,1452093213,l3,0,0 

i return values of second column in file "b.txt" values of first column in files "a.txt" , "b.txt" match (sort of inner join). if file in output file "c.txt", following output:

c.txt:

000000 000001 000002 000003 000004 000005 000007 000008 000009 000011 000012 000013 000016 000017 

notice these values don't exist second column in file "b.txt":

000006 000010 000014 000015 

i have tried looking on place couldn't quite find concrete solution. appreciate help.

thanks!

you can use awk:

awk -f '[, ]' 'fnr==nr{col1[$1]; next} $1 in col1{print $2}' a.txt b.txt 000000 000001 000003 000004 000005 000007 000008 000009 000011 000012 000013 000016 000017 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -