Producing differences between 2 text files

Posted on 2006-05-02
Last Modified: 2010-04-20
I would like to see the changes (only additions) that have been made since I last took a backup of a text file (eg.  /var/log/messages)

I tried "diff oldfile newfile", but that produces the wrong kind of output.  So I thought about doing a "wc -l" on the old file, then printing all the line from the result of wc -l, to the end of the file using sed.  This would probably work, but something inside me is nagging saying there's a better way of doing this.

Any ideas?

Steve :)
Question by:sda100
    LVL 12

    Accepted Solution

    maybe this:


    With no options, produce three-column output.  Column one contains
    lines unique to FILE1, column two contains lines unique to FILE2,
    and column three contains lines common to both files.

      -1              suppress lines unique to FILE1
      -2              suppress lines unique to FILE2
      -3              suppress lines that appear in both files
          --help     display this help and exit
          --version  output version information and exit


    comm -2 -3 /var/log/messages /var/log/messages.old
    LVL 34

    Expert Comment

    by:Duncan Roe
    What kind of difference output do you want if diff gives you "the wrong kind of output"? diff delineates what's inserted (or appened) c/w what's changed. Tell us what you *do* want and we'll see what we can do.
    LVL 9

    Author Comment

    Thanks for the replies.  The output I want is exactly what Heem14s answer gives.  ie. the extra lines between an archived copy of a log file, and the current copy.  In that example, you only need -3, and providing you have the larger file first, then the output is perfect.

    I'll leave this open for a day or two longer in case there are more replies.

    Steve :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
    Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now