在目录中搜索 MS word 文件以获取 Linux 中的特定内容 [英] Search MS word files in a directory for specific content in Linux

查看:21
本文介绍了在目录中搜索 MS word 文件以获取 Linux 中的特定内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个充满 MS Word 文件的目录结构,我必须在目录中搜索特定的字符串.到目前为止,我一直在使用以下命令在目录中搜索文件

I have a directory structure full of MS word files and I have to search the directory for particular string. Until now I was using the following command to search files for in a directory

找到.-exec grep -li 'search_string' {} ;

find . -exec grep -li 'search_string' {} ;

找到.-name '*' -print |xargs grep 'search_string'

find . -name '*' -print | xargs grep 'search_string'

但是,此搜索不适用于 MS Word 文件.

But, this search doesn't work for MS word files.

是否可以在 Linux 中的 MS Word 文件中进行字符串搜索?

Is it possible to do string search in MS word files in Linux?

推荐答案

我是一名翻译,对脚本编写几乎一无所知,但我对 grep 无法扫描我工作的 Word .doc 文件感到非常生气了解如何使这个小 shell 脚本使用 catdoc 和 grep 来搜索给定输入字符串的 .doc 文件目录.

I'm a translator and know next to nothing about scripting but I was so pissed off about grep not being able to scan inside Word .doc files that I worked out how to make this little shell script to use catdoc and grep to search a directory of .doc files for a given input string.

你需要安装catdocdocx2txt

#!/bin/bash
echo -e "

Welcome to scandocs. This will search .doc AND .docx files in this directory for a given string. 

Type in the text string you want to find... 
"
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

欢迎所有改进和建议!

这篇关于在目录中搜索 MS word 文件以获取 Linux 中的特定内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆