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

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

问题描述

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

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' {} \;

查找.名称'*'-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 "\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

欢迎所有改进和建议!

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

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