Noah Mendoza
Noah Mendoza

Reputation: 837

Windows equivalent of the unix diff command with ed output

I'm attempting to recursively compare two directories that are structurally equivalent (XML documents in a decompressed excel file), and if any files differ, then overwrite the text from the first file with the text from the corresponding file in the second directory. In the Unix command line, you can easily output a script that will do this for two files using:

diff -e file1.xml file2.xml > edscript.txt

I can then invoke the script with:

echo "w" >> edscript.txt
ed - file1.txt < edscript.txt

However, I'm using Git Bash Windows 7, and there is no "ed" program installed. Is there an equivalent that can output a script and execute? If not, is there a way to install ed on git bash? I've already tried sudo apt-get install ed but the commands don't seem to be possible. My ultimate goal is to run this scripts using python with the subprocess library

Any advice or suggestions are welcome. Thanks!

Upvotes: 0

Views: 3807

Answers (3)

cdarke
cdarke

Reputation: 44364

The GNU tools http://gnuwin32.sourceforge.net/packages/diffutils.htm

Also from cmd.exe the comp command, try help comp for parameters.

Edit: you have the python tag on this question, do you have python available? If so then look at the filecmp module in the standard library: https://docs.python.org/3/library/filecmp.html

Examples here: http://pymotw.com/2/filecmp/

Upvotes: 0

a p
a p

Reputation: 3208

If you have git bash installed already, check in its bin folder. There should be a diff.exe that you can call directly.

For me, that's C:\Program Files (x86)\Git\bin\diff.exe

(This is probably easier than trying to call a *nix-like shell from python on windows, and then run diff on that command line)

Edit: Doing this from python, assuming the aforementioned diff.exe path:

In [40]: import subprocess
In [41]: subprocess.call(["c:/program files (x86)/git/bin/diff.exe", "-e", "c:/users/a.p/empty.py", "c:/users/a.p/.bashrc"])
alias l='ls -a'
alias ll='ls -la'
alias ipy='ipython'
.
Out[41]: 1

Upvotes: 1

SingleNegationElimination
SingleNegationElimination

Reputation: 156158

Yes, these tools are available for windows, consider Cygwin or MSyS.

Upvotes: 0

Related Questions