Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two text files on a unix system

Tags:

unix

emacs

I am using Emacs on a GNU/Linux system. I am trying to compare two data files containing columns of numbers which are almost similar in content. Is there an Emacs/Unix utility to highlight the differences between these text files?

like image 937
smilingbuddha Avatar asked Sep 08 '12 20:09

smilingbuddha


People also ask

Which command is used to compare two files Unix?

cmp command in Linux/UNIX is used to compare the two files byte by byte and helps you to find out whether the two files are identical or not.

How do I compare data in two text files?

Using File Compare or the FC command in Command Prompt is another way if you need text or binary compare. The output is shown in Command Prompt and is not easy to read. For all file formats that Word can open, the Compare option in Word is the easiest to use. Windows 11 review: Is it better than Windows 10?

How do I compare two files side by side in Linux?

sdiff command in linux is used to compare two files and then writes the results to standard output in a side-by-side format. It displays each line of the two files with a series of spaces between them if the lines are identical.


1 Answers

In emacs, if you pull both files into different buffers, you can use the M-x ediff-buffers command to display the differences. Emacs will nicely highlight the differences and allow you to scroll through the buffers concurrently. See tip #5 on this "Ten Essential Emacs tips" page, or the GNU docs on Ediff.

Under Unix there's the diff command. Here's a short example of using diff, and one more example

I usually prefer comparing with Emacs, more visual, though of course both files will need to fit into buffers.

like image 87
Levon Avatar answered Sep 25 '22 02:09

Levon