Thangaraj
Thangaraj

Reputation: 3184

compare two files and save the difference in linux

I like to compare two text files and save the difference under linux.

I know there are tools like kdiff, diff vimdiff etc. but my expectation are as follows.

  1. Output should be in a separate file
  2. The difference should be quoted with colours, ex: delete line in red and added line in green something like that
  3. It should ignore space differences
  4. It should be an opensource tool

Upvotes: 0

Views: 4852

Answers (4)

ramwin
ramwin

Reputation: 6276

Save the changes to a file:

diff -Nur originalfile newfile > patchfile

Use the difference file to change the origin file:

patch originfile patchfile

I think this is the easiest way to save the changes and reload the changes. By the way, you can use this command the create an update-package.

Upvotes: 0

jørgensen
jørgensen

Reputation: 10549

Like,

#!/bin/bash
wdiff -w "\e[31m" -x "\e[0m" -y "\e[32m" -z "\e[0m" "$@";

replace \e by, well, the ASCII character with value 0x1A. Put the two commands into some file, and run it using redirection.

Upvotes: 0

crazy_prog
crazy_prog

Reputation: 1099

use tkdiff4 -w file-name1 file-name2

It fulfills all your requirements. Specific color might be an issue.

Upvotes: 1

zed_0xff
zed_0xff

Reputation: 33217

try colordiff and man diff for options for ignoring whitespace etc

Upvotes: 0

Related Questions