ms dos或cygwin下搜索docx文件的命令行工具

发布于 2024-12-25 06:22:10 字数 189 浏览 0 评论 0原文

有没有一个命令行工具可以在ms dos或cygwin下搜索docx文件?

我尝试过 grep,它不能与 docx 一起使用,而可以与 txt 文件一起正常工作。

我知道我总是可以先将 docx 转换为 txt,然后使用 grep 进行搜索,但我想知道

是否有一个命令工具可以直接在命令行下搜索?

谢谢

Is there a command line tool that is able to search docx file under ms dos or cygwin ?

I have tried grep, it's not working with docx while working fine with txt file.

I know I could always convert the docx to txt 1st then search using grep, but I am wondering

is there a command tool that I can search directly under command line?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

风尘浪孓 2025-01-01 06:22:10

我写了一个小的 bash 脚本,它可以帮助您:

#!/bin/bash
export DOCKEY="$@"

function searchdoc(){
 VK1=$(cat "$@" | grep -i "$DOCKEY" | wc -c)
 VK2=$(unzip -c "$@" | grep -i "$DOCKEY" | wc -c)
 let NUM=$VK1+$VK2
 if [ "$NUM" -gt 0 ]; then
  echo $NUM occurences in $@
  echo opening file. 
  gnome-open "$@"
 fi
}

export -f searchdoc
echo searching for $DOCKEY ...
find . -exec bash -c 'searchdoc "{}" 2>/dev/null' \;

将其保存为 docfind.sh,您可以

 $#> docfind.sh searchterm

从任何要扫描的文件夹中调用。

i wrote a small bash script, which would help you:

#!/bin/bash
export DOCKEY="$@"

function searchdoc(){
 VK1=$(cat "$@" | grep -i "$DOCKEY" | wc -c)
 VK2=$(unzip -c "$@" | grep -i "$DOCKEY" | wc -c)
 let NUM=$VK1+$VK2
 if [ "$NUM" -gt 0 ]; then
  echo $NUM occurences in $@
  echo opening file. 
  gnome-open "$@"
 fi
}

export -f searchdoc
echo searching for $DOCKEY ...
find . -exec bash -c 'searchdoc "{}" 2>/dev/null' \;

save it as docfind.sh and you can invoke

 $#> docfind.sh searchterm

from any folder you want to scan.

红玫瑰 2025-01-01 06:22:10

经过尝试后,我发现最简单的方法是使用 Linux 实用程序将所有 docx 文件批量转换为 txt 文件,然后轻松地对这些 txt 文件执行 grep 操作。

After a trying out the stuff , I found the easiest way to do this is to use a linux utility to batch convert all docx files into txt files, then do grep with those txt files easily.

森林迷了鹿 2025-01-01 06:22:10

zgrep 可能适合你?它通常在 OpenOffice 文档中工作,并且都是包含 XML 的压缩档案:

zgrep "some string" *.xdoc

我没有 .xdoc 文件来测试它,但理论上它应该工作......

zgrep might work for you? It usually works in OpenOffice documents, and both are compressed archives containing XML:

zgrep "some string" *.xdoc

I have no .xdoc files to test this with, but in theory it should work...

萌梦深 2025-01-01 06:22:10

您可以使用 zipgrep,它对 zip 存档(即 docx 文件)的所有文件调用 grep。
不过,您可能会对结果感到失望,因为它返回包含文本和 XML 标记的 XML 文件的原始内容。

You can use zipgrep, which calls grep on all files of a zip archive (which a docx file is).
You might be disappointed with the result, though, as it returns raw content of XML files containing both the text and XML tags.

メ斷腸人バ 2025-01-01 06:22:10

保存为docfind.sh即可调用

像我这样的新手可能需要被告知,要使 .sh 脚本可以从任何目录执行,它需要具有 可执行属性集 并位于 /usr/bin 或 路径

我能够在 Linux Mint 中设置 nemo 文件管理器,从任何文件夹的上下文菜单中打开终端 (信息在此)。

save it as docfind.sh and you can invoke

Newbies like me might need to be told that for the .sh script to be executable from any directory, it needs to have the executable property set and be located in /usr/bin or elsewhere in your Path.

I was able to set up the nemo file manager in Linux Mint to open a terminal from any folder's context menu (information here).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文