Compare two files and print difference

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • siva murugan
    New Member
    • Aug 2010
    • 1

    Compare two files and print difference

    Hello Experts

    I have two files file1 and file2, both have IP addresses.
    Basically i want a comparison in which i can get any new IPs present in file2 when compared it with file1 and viceversa.

    Example:
    File1
    172.30.80.1
    172.30.80.2
    172.30.80.3
    172.30.80.21
    172.30.80.22
    172.30.80.23
    172.30.80.25
    172.30.80.27
    172.30.80.28
    172.30.80.29
    172.30.80.30
    172.30.80.31
    172.30.80.32
    (up to 650 plus IP's)

    File2:

    have lot of IPs same as file but some new IP's too which may not present in file1.

    So how to compare both files using perl or any other unix script.

    I'm a newbie as far as scripting is considered, Please help.

    Thanks
    Siva Murugan
  • toolic
    Recognized Expert New Member
    • Sep 2009
    • 70

    #2
    Since you are on unix, you can use sort and comm. comm will show you which IPs are present in both files and which are unique to both files.

    Comment

    Working...