File1
(keywords present in it (after 2nd comma) for picking Ex: GOLD, BRO, ...)
File2
(extraction of lines from here)
File1:
ABC,123,GOLD,20171201,GOLDFUTURE
ABC,467,SILVER,20171201,SILVERFUTURE
ABC,987,BRO,20171201,BROFUTURE
File2:
XYZ,32,RUBY,20171201,RUBY
XYZ,33,GOLD,20171201,GOLD
XYZ,34,CEMENT,20171201,CEMENT
XYZ,35,PILLAR,20171201,pillar
XYZ,36,CNBC,20171201,CNBC
XYZ,37,CBX,20171201,CBX
XYZ,38,BRO,20171201,BRO
I want Linux commands(awk-sed-cat-grep etc) to get output file: which is:
XYZ,33,GOLD,20171201,GOLD
XYZ,38,BRO,20171201,BRO
I have found commands online:
grep -F -f File1 File2
awk 'FNR==NR {a[$0];next} ($NF in a)' File1 File2
awk 'FNR==NR {a[$0];next} ($0 in a)' File1 File2
diff File1 File2
In the point 3. I am picking up whole lines from File1
for comparison, is there any way to pickup a keyword after comma? Or is there any way to insert File separator in the awk
command of point 2.