我有一个充满MS word文件的目录结构,我必须在目录中搜索特定的字符串.到目前为止,我使用以下命令在目录中搜索文件
find . -exec grep -li ‘search_string’ {} \;
find . -name ‘*’ -print | xargs grep ‘search_string’
但是,此搜索不适用于MS word文件.
是否可以在Linux中的MS word文件中进行字符串搜索?
解决方法:
我是一名翻译,并且几乎不知道脚本编写,但我很生气,因为grep无法扫描Word .doc文件,我研究了如何使这个小shell脚本使用catdoc和grep来搜索目录.doc文件的给定输入字符串.
您需要安装catdocand docx2txt包
#!/bin/bash
echo -e "\n
Welcome to scandocs. This will search .doc AND .docx files in this directory for a given string. \n
Type in the text string you want to find... \n"
read response
find . -name "*.doc" |
while read i; do catdoc "$i" |
grep --color=auto -iH --label="$i" "$response"; done
find . -name "*.docx" |
while read i; do docx2txt < "$i" |
grep --color=auto -iH --label="$i" "$response"; done
欢迎所有改进和建议!
标签:linux,unix,ms-word
来源: https://codeday.me/bug/20191006/1860465.html