grep for * .odt或* .doc文件中的文本?
如何在Ubuntu中搜索包含特定文本的* .odt或* .doc文件?
我使用grep -rl
,但这仅适用于文本文件。
注意:使用grep(例如searchmonkey)的解决方案将无法工作,因为* .doc或* .odt文件具有特殊格式。
从如何搜索文件夹中的文件内的字符串?
- Recoll想要索引我的主目录,但我想搜索特定目录中的* .odt文件; 我无法弄清楚如何用这个工具做到这一点。
- Searchmonkey似乎是grep的GUI,正如我所提到的,grep不适用于* .doc或* .odt文件。
- Regexxer也有同样的问题。
从搜索ODT文档而不打开它们?
- 像Recoll一样,我无法弄清楚如何使用此工具搜索特定目录中的* .odt文件。
catdoc
似乎在16.04递归地为.doc
文件工作: https : catdoc
没有提到.docx
所以你需要自己解决这个问题。
对于.ods
或.odt
文件,您可以使用以下脚本由kaibob @ ubuntuforums.org提供 :
#!/bin/bash find . -type f -name "*.od*" | while read i ; do [ "$1" ] || { echo "You forgot search string!" ; exit 1 ; } unzip -ca "$i" 2>/dev/null | grep -iq "$*" if [ $? -eq 0 ] ; then echo "string found in $i" | nl fi done
假设您将其称为“libre-search”并使其可执行。
然后,运行libre-search your_string
应列出包含your_string的文件。
unzip -ca "$i" 2>/dev/null
处理不需要的内容。
grep -iq
使搜索不区分大小写。
nl
对输出进行编号。