Monday, 15 September 2014

linux - Display duplicate lines in two different files -


I have two files and I would like to display the duplicate line I tried to do it but it does not work:

cat id1.txt | While reading the ID; Grep "$ id" id2.txt; Done

I am thinking that there is no other way to display duplicate lines in the file. I have a list of IDs in both files.

files sorted? Can they be sorted?

If sorted:

  comm-12 id1.txt id2.txt   

bash 4.x:

  comm-12 & lt; (Sort id 1.txt) & lt; (Sort id 2.txt)   

If you do not have bash 4.x and can not be resolved using temporary files.

You can type grep -F :

  grep -F -f id1.txt id2.txt   

It appears in the words of id1.txt which appears in id2.txt . Only one problem here is making sure that no ID 1 matches any ID containing 1 anywhere. Available in some versions the -w or -x options will work here.

No comments:

Post a Comment