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!

3
  • Can you find something on answer about PowerShell ? Commented May 27, 2015 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. Commented May 27, 2015 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 or xml compare. Commented May 27, 2015 at 18:51

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

6 Comments

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?
@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.
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.
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 gnuwin32.sourceforge.net/packages/ed.htm - any issues surrounding that might deserve their own question.
Alright, thank you so much. This is at least enough to get some momentum. I appreciate it!
|
0

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

1 Comment

Thanks, I'm looking through both of them now. Might be of use!
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/

2 Comments

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.
@NoahMendoza: added an edit mentioning python filecmp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.