linux - How to find matching patterns between two text files and output to another file? -



linux - How to find matching patterns between two text files and output to another file? -

i have 2 text files different text organization. both files contain few identical patterns (numbers) in text. i'd find patterns (numbers) nowadays in both files , write them output file.

file1.txt:

blablabla_25947.bkwjcnwelkcnwelckme blablabla_111.bkwjcnwelkcnwelckme blablabla_65155.bkwjcnwelkcnwelckme blablabla_56412.bkwjcnwelkcnwelckme

file2.txt:

blablabla_647728.bkwjcnwelkcnwelck kjwdhcwkejcwmekcjwhemckwejhcmwekch blablabla_6387.bkwjcnwelkcnwelckme wexkwhenqlciwuehnqweiugfnwekfiugew wedhwnejchwenckhwqecmwequhcnkwjehc owichjwmelcwqhemclekcelmkjcelkwejc blablabla_59148.bkwjcnwelkcnwelckme ecmwequhcnkwjehcowichjwmelcwqhemcle kcelmkjcelkwejcwecawecwacewwawwaxeg blablabla_111.bkwjcnwelkcnwelckm wesetrbrvsscqesfdveradassefwaefawecc

output_file.txt:

111

how about:

$ egrep -o '_[0-9]+\.' file1 | grep -of - file2 | tr -d '_.' 111 # redirect new file $ egrep -o '_[0-9]+\.' file1 | grep -of - file2 | tr -d '_.' > file3

first grep gets digit strings (preceded _ , preceding .) file1 , list used grep matches in file2. _ , . stripped using tr.

linux bash shell unix grep

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -