如何在 Ubuntu 中搜索包含特定文本的 *.odt 或 *.doc 文件?
我使用grep -rl <text to search for>,但这仅适用于文本文件。
注意:使用 grep(例如 searchmonkey)的解决方案将不起作用,因为 *.doc 或 *.odt 文件具有特殊格式。
DK *_*ose 14
catdoc似乎对.doc16.04 中的文件递归工作:https : //superuser.com/questions/330242/how-to-recursively-find-a-doc-file-that-contains-a-specific-word
没有提到,.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
Run Code Online (Sandbox Code Playgroud)
假设您将其称为“libre-search”并使其可执行。
然后,运行libre-search your_string应该列出包含your_string 的文件。
unzip -ca "$i" 2>/dev/null处理不需要的内容。
grep -iq使搜索不区分大小写。
nl编号输出。
| 归档时间: |
|
| 查看次数: |
8905 次 |
| 最近记录: |