Skip to content


comparing contents of text files

Well, how many times have I been asked to do just that and how many times have I done it comparing both files one by one? How many times have I been asked to list duplicates in a file and used my eyes to do that? Many times indeed, but not any more!

To compare two files, to find duplicate entries in both – first, make sure that both files are already sorted in alphabetical order and then execute:

# uniq -d file1 file2

To find duplicates (if any) in the file /etc/passwd (for example):

# cat /etc/passwd | awk -F ':' '{print $1}' | sort | uniq -d

or

sort -t ':' -k 1 /etc/passwd | awk -F ':' '{print $1}' | uniq -d

The one who knows a shorter syntax, please leave a comment.

Posted in Real life AIX.

Tagged with , , .


2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Dan says

    You could use cut…
    cut -f 1 -d : /etc/passwd | sort | uniq -d

  2. ThinkDifferently says

    cut -d: -f1 /etc/passwd | sort | uniq -d



Some HTML is OK

or, reply to this post via trackback.

WordPress Anti Spam by WP-SpamShield



Copyright © 2015 - 2016 Waldemar Mark Duszyk. - best viewed with your eyes.. Created by Blog Copyright.