如何在多个 DOCX 文件中搜索 Word 字段中的字符串?
How to search multiple DOCX files for a string within a Word field?
是否有任何 Windows 应用程序可以在 Word (DOCX) 文档的字段中搜索文本字符串? Agent Ransack 及其大哥 FileLocator Pro 等应用程序可以在 Word 文档中查找字符串,但似乎无法在字段内进行搜索。
例如,我希望能够在 Word 文档集合中找到所有出现的字符串 "getProposalTranslations",这些文档的字段语法如下:
{ AUTOTEXTLIST \t "<wr:out select='$.shared_quote_info' datasource='getProposalTranslations'/>" }
请注意,字符串不会出现在文档本身的文本中,而只会出现在字段中。我相信,本质上 DOCX 文件只是一个 zip 文件,所以如果有一个可以在存档中进行 grep 的工具,那可能会起作用。另请注意,我需要能够在许多目录中搜索成百上千个文件,因此一个一个地解压缩文件是不可行的。我自己没有找到任何东西,我想我会在这里问。提前致谢。
此脚本应该可以完成您要执行的操作。如果情况并非如此,请告诉我。我通常不会编写完整的脚本,因为它会影响学习过程,所以我对每个命令都进行了注释,以便您可以从中学习。
#!/bin/sh
# Create ~/tmp/WORDXML folder if it doesn't exist already
mkdir -p ~/tmp/WORDXML
# Change directory to ~/tmp/WORDXML
cd ~/tmp/WORDXML
# Iterate through each file passed to this script
for FILE in $@; do
{
# unzip it into ~/tmp/WORDXML
# 2>&1 > /dev/null discards all output to the terminal
unzip $FILE 2>&1 > /dev/null
# find all of the xml files
find -type f -name '*.xml' | \
# open them in xmllint to make them pretty. Discard errors.
xargs xmllint --recover --format 2> /dev/null | \
# search for and report if found
grep 'getProposalTranslations' && echo " [^ found in file '$FILE']"
# remove the temporary contents
rm -rf ~/tmp/WORDXML/*
}; done
# remove the temporary folder
rm -rf ~/tmp/WORDXML
将脚本保存在任何你喜欢的地方。随心所欲地命名。我将其命名为docxfind
。通过 运行ning chmod +x docxfind
使其可执行。然后你可以 运行 这样的脚本(假设你的终端是 运行ning 在同一目录中): ./docxfind filenames...
是否有任何 Windows 应用程序可以在 Word (DOCX) 文档的字段中搜索文本字符串? Agent Ransack 及其大哥 FileLocator Pro 等应用程序可以在 Word 文档中查找字符串,但似乎无法在字段内进行搜索。
例如,我希望能够在 Word 文档集合中找到所有出现的字符串 "getProposalTranslations",这些文档的字段语法如下:
{ AUTOTEXTLIST \t "<wr:out select='$.shared_quote_info' datasource='getProposalTranslations'/>" }
请注意,字符串不会出现在文档本身的文本中,而只会出现在字段中。我相信,本质上 DOCX 文件只是一个 zip 文件,所以如果有一个可以在存档中进行 grep 的工具,那可能会起作用。另请注意,我需要能够在许多目录中搜索成百上千个文件,因此一个一个地解压缩文件是不可行的。我自己没有找到任何东西,我想我会在这里问。提前致谢。
此脚本应该可以完成您要执行的操作。如果情况并非如此,请告诉我。我通常不会编写完整的脚本,因为它会影响学习过程,所以我对每个命令都进行了注释,以便您可以从中学习。
#!/bin/sh
# Create ~/tmp/WORDXML folder if it doesn't exist already
mkdir -p ~/tmp/WORDXML
# Change directory to ~/tmp/WORDXML
cd ~/tmp/WORDXML
# Iterate through each file passed to this script
for FILE in $@; do
{
# unzip it into ~/tmp/WORDXML
# 2>&1 > /dev/null discards all output to the terminal
unzip $FILE 2>&1 > /dev/null
# find all of the xml files
find -type f -name '*.xml' | \
# open them in xmllint to make them pretty. Discard errors.
xargs xmllint --recover --format 2> /dev/null | \
# search for and report if found
grep 'getProposalTranslations' && echo " [^ found in file '$FILE']"
# remove the temporary contents
rm -rf ~/tmp/WORDXML/*
}; done
# remove the temporary folder
rm -rf ~/tmp/WORDXML
将脚本保存在任何你喜欢的地方。随心所欲地命名。我将其命名为docxfind
。通过 运行ning chmod +x docxfind
使其可执行。然后你可以 运行 这样的脚本(假设你的终端是 运行ning 在同一目录中): ./docxfind filenames...