Rabu, 16 November 2011

Linux Diff Command

How Do I Compare Two Files and Show The Differences?

Read more:http://lowfatlinux.com/linux-compare-files-diff.html#ixzz1drvISIqk

If, when you usefind, you discover two files with suspiciously similar names, you might want to know whether they really contain the same information. Thediffcommand will compare two files and give you the lowdown on just how different they are. Here's an example of how you would use thediffcommand and the output you might get from it:

Read more:http://lowfatlinux.com/linux-compare-files-diff.html#ixzz1druy5BPL




diff cookies.old cookies.new
5c5
< One cup vanilla extract
---
> One teaspoon vanilla extract
7d6
< Six ounces chopped liver
21a22
> Note: The previous version of this recipe had a few errors!


The output is actually a description of how to transform the old file into the new one. Here,diffis telling you three things:
�The fifth line of the file has undergone a change. The5c5message says to replace line 5 of the old file with line 5 of the new file. Both the old and new text are displayed, separated by a line of three dashes. (The less-than (<) notation means "remove this line," and the greater-than (>) sign means "add this line.")
�Line 7 of the old file does not appear in the new file. The7d6message says to delete line 7 from the old file, and the files will then be in sync, starting at line 6 of the new file. The text to be deleted is displayed on the next line.
�A line was added to the new file. The21a22message says to add a new line after line 21 of the old file. The text to be added is displayed on the final line of the output.
Two useful flags you can specify when comparing files are-b(ignore blanks) and-i(ignore case). You can use them separately or in combination. The ignore blanks feature is especially useful when you're comparing the source code for two programs, since indentation changes are rarely significant. For example, here's how you might compare two program files,ur2cool.candur2cool.backup:
diff -b -i ur2cool.c ur2cool.backup
Don't worry if you have some difficulty understanding the output of thediffcommand. It's c ryptic because it was designed to be used by computers, not humans. (Some source-code control systems used by programmers usediffto keep a record of the changes made to a program over time.)
Do pay attention, though, to the less-than and greater-than indicators to see at a glance what was added or deleted; and be happy if you manage to get a general feeling for the ways the files differ.


Read more:http://lowfatlinux.com/linux-compare-files-diff.html#ixzz1drv7TAVe

Tidak ada komentar:

Posting Komentar