6

我一直在关注本指南,了解如何区分 Microsoft Word 文档,但我遇到了这个错误:

Usage:  /usr/bin/docx2txt.pl [infile.docx|-|-h] [outfile.txt|-]
        /usr/bin/docx2txt.pl < infile.docx
        /usr/bin/docx2txt.pl < infile.docx > outfile.txt

        In second usage, output is dumped on STDOUT.

        Use '-h' as the first argument to get this usage information.

        Use '-' as the infile name to read the docx file from STDIN.

        Use '-' as the outfile name to dump the text on STDOUT.
        Output is saved in infile.txt if second argument is omitted.

Note:   infile.docx can also be a directory name holding the unzipped content
        of concerned .docx file.

fatal: unable to read files to diff

为了解释我是如何得出这个错误的:我在我想要区分的存储库中创建了一个 .gitattributes 。.gitattributes 看起来像这样:

*.docx diff=word
*.docx difftool=word

我已经安装了 docx2txt。我在Linux上。我创建了一个名为 docx2txt 的文件,其中包含以下内容:

#!/bin/bash
docx2txt.pl $1 -

$ chmod a+xdocx2txt 我把 docx2txt 放在 /usr/bin/

我做了:

$ git config diff.word.textconv docx2txt

然后试图区分两个微软的word文档。那是我得到上面提到的错误的时候。

我错过了什么?如何解决此错误?

PS:我不知道我的 shell 是否可以找到 docx2txt 因为当我这样做时:

$ docx2txt

我的终端冻结,处理某些东西,但不输出任何东西,当我执行这些命令时,会发生这种情况:

$ man docx2txt
No manual entry for docx2txt
$ docx2txt --help
Can't read docx file <--help>!

更新进度:我将 docx2txt 更改为

#!/bin/bash
docx2txt.pl "$1" -

正如 pmod 建议的那样,现在git diff <commit>可以从命令行工作!耶!但是,当我尝试

$ git difftool <commit>

git 启动 kdiff3,我得到这个弹出错误:

Some input characters could not be converted to valid unicode.
You might be using the wrong codec. (e.g. UTF-8 for non UTF-8 files).
Don't save the result if unsure. Continue at your own risk.
Affected input files are in A, B.

...文件中的所有字符都是胡说八道。命令行正确显示差异文本,但由于某种原因 kdiff3 没有正确显示差异文本。

如何在 kdiff3 或其他 gui 工具中正确显示差异文本?我应该将 kdiff3 更改为另一个工具吗?

额外:由于这些命令,我​​的 shell 似乎无法找到 docx2txt:

$ which doctxt
which: no doctxt in (/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)

$ which docx2txt
/usr/bin/docx2txt
4

2 回答 2

4

doc2txt.pl根据使用情况需要两个参数或零。在第一个(您的)案例中,参数是文件名或“-”。因此,当文件名中至少有一个空格作为第一个参数传递时,您的包装脚本看起来是正确的。在这种情况下,扩展后的$1文件名部分将作为单独的参数传递,因此工具会输出使用信息,因为它读取了超过 2 个参数。

尝试使用引号来避免文件名拆分:

#!/bin/bash
docx2txt.pl "$1" -

PS:不知道我的shell能不能找到docx2txt

你可以检查这个

$ which docx2txt

如果您看到路径,则可以找到工具(二进制或可运行脚本)(基于 PATH 环境变量)。

因为当我这样做时:

$ docx2txt

我的终端冻结,处理某些东西,但不输出任何东西

如果没有参数,您的脚本将执行doc2txt.pl -根据工具的使用,它需要通过 STDIN 传递的输入文件,即您正在输入的内容。因此,它看起来像是挂起和处理某些东西,但实际上只捕获您的输入。

于 2015-12-01T23:19:18.777 回答
3

您可以使用 pandoc 转换为降价

pandoc -f docx -t markdown -o outfile.md infile.docx

然后使用 meld 这是一个很棒的 gui,比较文件

https://askubuntu.com/questions/515900/how-to-compare-two-files

于 2017-01-17T13:56:27.050 回答