0

Suppose i have 2 config files such as: file 1:

smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes
virtual_gid_maps = static:5000

File 2:

virtual_gid_maps = static:5000
broken_sasl_auth_clients = yes
smtpd_sasl_authenticated_header = yes

if you see carefully, you'll see together have a line begin with virtua_gid_* but file 1 have it in end of file but file 2 have it head of file.

Suppose i have 2 files with same lines with difference positions , but positions not important for me, to be or not to be is important.

HOW CAN I COMPARE MY FILES?

3 Answers 3

6

If the positions are not important, you can sort the files and then, perform a diff. You will have to save the sorted files in temporary area.

sort file1 > /tmp/file1
sort file2 > /tmp/file2
diff /tmp/file1 /tmp/file2

You may also want to try vimdiff instead of diff.

3

If the files have only simple <name> = <value> lines into (like your example) you can do something like this:

$ cat file1 | sort > /tmp/sortedfile1
$ cat file2 | sort > /tmp/sortedfile2
$ diff /tmp/sortedfile1 /sortedfile2

This will work as long there is the same number of spaces around =

6
  • There's no need to pipe cat into sort since sort accepts a filename as an argument.
    – j883376
    Jun 19, 2013 at 14:18
  • How is this different to the answer already posted by @unxnut? Apart from the useless use of cat of course.
    – terdon
    Jun 19, 2013 at 14:19
  • @terdon It's possible that it was being written while unxnut's was posted.
    – j883376
    Jun 19, 2013 at 14:21
  • @j883376 ah, yes indeed, fair enough.
    – terdon
    Jun 19, 2013 at 14:21
  • 1
    @DavAlPi you don't have to do anything. I have to learn to be more patient with people.
    – terdon
    Jun 19, 2013 at 14:25
3

You can avoid using temp files if you use sub shells:

diff <(sort fileA) <(sort fileB)

Another useful program is meld which is a very nice GUI for diff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.