Let's say I have two text files that I need to extract data out of. The text of the two files is as follows:
File1.txt
ami-1234567
ami-1234567654
ami-23456
File-2.txt
ami-1234567654
ami-23456
ami-2345678965
I want all the data of file2.txt which looks same from file1.txt.
CodePudding user response:
Did you try join
?
join -o 0 File1.txt File2.txt
ami-1234567654
ami-23456
remark: For join
to work correctly, it needs your files to be sorted, which seems to be the case here.
CodePudding user response:
I don`t know if I proper understand You:
but You can Try sort this files (after extract):
sort file1 > file1.sorted
sort file2 > file2.sorted