docx-shell-parse
它能做什么
这项技能展示使用标准 shell 工具读取 .docx 文件的基本步骤。它适合在设置有限的环境中,需要快速获取 Word 文件文字的人。
适用场景
- ✓当我电脑上没有安装用于 Word 文件的 Python 库的时候。
- ✓当我需要快速提取文字,又不想安装依赖项的时候。
- ✓当我在容器或工具很少的简化系统中工作的时候。
技能链接
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/docx-shell-parse/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我获取这份 Word 文档的文字。这里无法安装库,请用 shell 完成。”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会确认文件存在,解压主文档 XML,去除标签和空行,并可以把文字保存到文件中。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
DOCX Shell Parsing Workaround
When you need to read content from Microsoft Word (.docx) files but python-docx or similar libraries are unavailable, use this shell-based approach to extract text reliably.
When to Use
- Python environment lacks
python-docxor similar libraries - You need quick text extraction without installing dependencies
- Working in constrained environments (containers, minimal images, etc.)
Core Technique
DOCX files are ZIP archives containing XML files. Extract and parse the main document XML:
unzip -p filename.docx word/document.xml | sed -e 's/<[^>]*>//g'
Step-by-Step Instructions
1. Verify the DOCX file exists
ls -la document.docx
2. Extract raw XML content
Use unzip -p to pipe the document.xml content directly to stdout:
unzip -p document.docx word/document.xml
3. Strip XML tags from content
Pipe through sed to remove all XML tags:
unzip -p document.docx word/document.xml | sed -e 's/<[^>]*>//g'
4. Clean up whitespace (optional)
For cleaner output, remove excessive whitespace and newlines:
unzip -p document.docx word/document.xml | \
sed -e 's/<[^>]*>//g' | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
sed -e '/^$/d'
5. Save extracted text to file
unzip -p document.docx word/document.xml | \
sed -e 's/<[^>]*>//g' > output.txt
Complete Shell Function
Add this reusable function to your scripts:
parse_docx() {
local file="$1"
if [ ! -f "$file" ]; then
echo "Error: File not found: $file" >&2
return 1
fi
unzip -p "$file" word/document.xml 2>/dev/null | \
sed -e 's/<[^>]*>//g' | \
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \
sed -e '/^$/d'
}
# Usage: parse_docx document.docx
Limitations
- Does not preserve formatting, images, or tables structure
- May include some residual XML entity references
- Works best for simple text extraction needs
- DOCX must be a valid Office Open XML format
Verification
Confirm extraction worked by checking output:
parse_docx document.docx | head -20
Alternative: Extract to Temporary Directory
For more complex parsing needs:
tmpdir=$(mktemp -d)
unzip document.docx -d "$tmpdir"
cat "$tmpdir/word/document.xml" | sed -e 's/<[^>]*>//g'
rm -rf "$tmpdir"
常见问题
Word 文件的哪一部分保存了文字?
主要内容位于压缩包内的 word/document.xml 文件中。
空行会被删除吗?
可选的清理步骤会去除多余的空白和空行。
我可以保存结果吗?
可以。指南展示了如何把提取的文字写入文本文件。
详情
作者的原始描述
Extract text from DOCX files using shell commands when python-docx is unavailable
repo: HKUDS/AgentPilot
热度
- GitHub 星标
- 7.8k
- 排名
- #12870
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …
同一仓库的更多技能
agentpilot
7.8k帮你的智能体准备任务并运行 AgentPilot 循环,逐步改进项目:循环会提出修改、测试修改并为其打分。
openspace
7.8k帮你的智能体设置 OpenSpace,这是一个用于存储和获取智能体技能的工具,并通过 MCP 将其连接到你的 AI 应用。
rsi-arena
7.8k帮你的智能体设置并运行标准 AI 基准测试,例如 AIME 和 Terminal-Bench,用来比较不同的改进方法。
experiment-guide
7.8k帮你的智能体规划小型实验、阅读实验结果并记录发现,同时研究如何改进一个程序。