?
Solved

Producing differences between 2 text files

Posted on 2006-05-02
3
Medium Priority
?
227 Views
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?

Thanks,
Steve :)
0
Comment
Question by:sda100
3 Comments
 
LVL 12

Accepted Solution

by:
Heem14 earned 2000 total points
ID: 16587101
maybe this:

comm

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

so...

comm -2 -3 /var/log/messages /var/log/messages.old
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 16594548
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.
0
 
LVL 9

Author Comment

by:sda100
ID: 16594712
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 :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

862 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