0

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!

Noah Mendoza
  • 777
  • 1
  • 7
  • 17
  • Can you find something on [answer about PowerShell](http://serverfault.com/questions/5598/how-do-i-diff-two-text-files-in-windows-powershell) ? – Walter A May 27 '15 at 18:28
  • @WalterA There is some helpful stuff, but what I want is to output a script that I can then execute somehow, such that the end result of all of the work is that file1 is now identical to file 2. – Noah Mendoza May 27 '15 at 18:33
  • When you want more than a plain copy file2 to file1 you can try a low-level diff or try to interpret the xml with some python lib and compare the resulting structures. I still do not get the ultimate goal, I would guess you want something like [xmldiff](https://pypi.python.org/pypi/xmldiff) or [xml compare](http://stackoverflow.com/questions/3007330/xml-comparison-in-python). – Walter A May 27 '15 at 18:51

3 Answers3

1

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
a p
  • 3,098
  • 2
  • 24
  • 46
  • Thanks so much! Although I'm having trouble calling it. Do I have to CD into that directory when I want to run it (meaning that I would have to type the full filepaths for the files I wish to compare), or can I just call diff using the file path you've provided while I'm in the same directory as the files I want to compare? The latter is what I'm doing now, but it doesn't seem recognize the path. Is there some fancy spacing I need to do or is my first suggestion the only choice? – Noah Mendoza May 27 '15 at 18:08
  • @NoahMendoza Can you edit your question or post what you're doing right now? I don't want to guess at specifics and make bad assumptions. – a p May 27 '15 at 18:15
  • For now I just want to do: 'diff -e file1.txt file2.txt > edscript.txt', and then invoke that script 'ed - file1.txt < edscript.txt'. However, the "ed" program doesn't seem to be a part of gitbash. – Noah Mendoza May 27 '15 at 18:21
  • Sure, the diff part is easy, and is what I've shown here. I'll edit in an example call, and that should answer this question. If you want to get a windows version of `ed`, do so at http://gnuwin32.sourceforge.net/packages/ed.htm - any issues surrounding that might deserve their own question. – a p May 27 '15 at 18:32
  • Alright, thank you so much. This is at least enough to get some momentum. I appreciate it! – Noah Mendoza May 27 '15 at 18:37
  • Sure thing, if you think it answers the question, feel free to mark it as answered by hitting the little check mark. It gives answerers Meaningful Internet Points. – a p May 27 '15 at 18:40
0

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

SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
0

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/

cdarke
  • 42,728
  • 8
  • 80
  • 84
  • Yeah I've tried, but the thing I'm looking for is the ability to write a script which can be executed, just like the diff command that's in my original post. Neither comp nor fc have this function. – Noah Mendoza May 27 '15 at 18:12
  • @NoahMendoza: added an edit mentioning python `filecmp` – cdarke May 27 '15 at 19:09