Project Home


Author: Martin Blais <>
Version: 857


Useful script to conditionally replace a original by a generated file.

Table of Contents


Useful script to conditionally replace a original by a generated file.

Basically, you invoke some script or pipeline of scripts to perform modifications on an original text file and store the results in a temporary file (the modified-file), and then invoke this script to conditionally overwrite the contents of the orig-file with those of the modified file.

This works like copy (cp), except that xxdiff is shown to ask the user whether to copy the file or not. This is useful to run in a loop, for example:

for i in `*/*.xml` ; do
   cat $i | ...pipeline of cmds that modifies the file... > /tmp/out.xml
   # copy only if the user accepts or merges.
   xxdiff-cond-replace $i /tmp/out.xml

IMPORTANT: Notice well that the original file which will be overwritten is on the LEFT side. The syntax is reversed that of the UNIX cp command.

Exit Status

This program exits with status 0 if the copy operation was accepted or merged, with 1 otherwise.


  • the script automatically creates backup files.
  • the script automatically generates a detailed log of its actions and a text summary of all the differences beteween the original and new files.
  • the script can optionally checkout the file with ClearCase before performing the replacement.


xxdiff-cond-replace [<options>] <orig-file> <modified-file>


--version             show program's version number and exit
-h, --help            show this help message and exit
--command=COMMAND     xxdiff command prefix to use.
-b CHOICE, --backup-type=CHOICE
                      selects the backup type ('parallel', 'other', 'none')
                      specify backup directory for type 'other'
-C, --checkout-clearcase
                      checkout files with clearcase before storing.
-n, --dry-run         print the commands that would be executed but don't
                      really run them.
-q, --silent, --quiet
                      Do not output anything. Normally the decision status
                      and backup file location is output.
-x, --diff            Run a diff and log the differences on stdout.
-d, --delete          Instead of copying the temporary file, move it (delete
                      it after copying).
-X, --no-confirm      do not ask for confirmation with graphical diff
                      viewer. This essentially generates a diff log and
                      copies the file over with backups.


Download program here.



Copyright (C) 2003-2004 Martin Blais <>. This code is distributed under the terms of the GNU General Public License.