Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare two files ignoring order

Tags:

bash

unix

diff

I have two files which the order of lines is irrelevant, and I want to compare its content.

I looked into diff documentation but could not find anything like --ignore-order.

Any tips?

like image 739
RSFalcon7 Avatar asked May 22 '12 18:05

RSFalcon7


People also ask

How can I compare the contents of two files?

Right-click on the first file. Click on “Select for Compare” from the menu. Proceed to right-click on the second file. Click on “Compare with Selected.


1 Answers

Sort the files first:

$ sort file1 > file1.sorted $ sort file2 | diff - file1.sorted 

Also, although I personally discourage this sort of thing, if you are using bash and this feature is enabled on your system you can avoid the temporary file by using a process substitution:

$ diff <(sort file1) <(sort file2) 
like image 151
William Pursell Avatar answered Sep 22 '22 00:09

William Pursell