docx-shell-extract
できること
このスキルは、標準のコマンドラインツールを使って、.docxファイルを解凍し、マークアップを取り除いて読む方法を示します。追加のソフトウェアを入れずにWordのテキストが必要な人向けです。
使う場面
- ✓パソコンに、python-docxなどのライブラリがないとき。
- ✓追加のインストールなしで、Wordファイルから素早くテキストを抜き出したいとき。
- ✓環境が制限されていて、シェルのツールしか使えないとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/docx-shell-extract/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このWordファイルのテキストが必要ですが、追加のソフトウェアは入れられません。コマンドラインを使って取り出してもらえますか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
.docxファイルは、XMLを含むzipアーカイブです。AIは、主な文書のXMLを取り出し、タグと空行を取り除いて、結果をプレーンテキストとして保存します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
DOCX Shell Extraction
When to Use This Skill
Use this pattern when you need to read or extract text from Microsoft Word (.docx) files in constrained environments where:
- The
python-docxlibrary is not available - You cannot install additional Python packages
- You need a quick, reliable shell-based solution
Core Technique
DOCX files are ZIP archives containing XML files. The main document content is stored in word/document.xml. You can extract and parse this using standard shell tools.
Step-by-Step Instructions
Step 1: Extract the document.xml content
unzip -p filename.docx word/document.xml
The -p flag pipes the content to stdout without extracting to disk.
Step 2: Strip XML tags to get plain text
unzip -p filename.docx word/document.xml | sed 's/<[^>]*>//g'
This removes all XML tags, leaving the text content.
Step 3: Clean up whitespace (optional)
For cleaner output, add additional sed processing:
unzip -p filename.docx word/document.xml | \
sed 's/<[^>]*>//g' | \
sed 's/&[^;]*;//g' | \
sed 's/^[[:space:]]*//' | \
sed 's/[[:space:]]*$//' | \
sed '/^$/d'
This removes:
- XML tags
- XML entities (like
&,<) - Leading/trailing whitespace
- Empty lines
Step 4: Save to a text file (optional)
unzip -p filename.docx word/document.xml | \
sed 's/<[^>]*>//g' > output.txt
Complete Example
# Extract text from a Word document
DOCX_FILE="report.docx"
OUTPUT_FILE="report_text.txt"
unzip -p "$DOCX_FILE" word/document.xml | \
sed 's/<[^>]*>//g' | \
sed 's/&[^;]*;//g' | \
sed '/^$/d' > "$OUTPUT_FILE"
echo "Extracted text saved to $OUTPUT_FILE"
Verification
After extraction, verify the content was captured:
# Check if output file has content
if [ -s "$OUTPUT_FILE" ]; then
echo "Successfully extracted $(wc -l < "$OUTPUT_FILE") lines"
head -5 "$OUTPUT_FILE"
else
echo "Warning: Output file is empty"
fi
Limitations
- This method extracts raw text without formatting
- Complex layouts, tables, and images are not preserved
- Some special characters may need additional handling
- Works best for text-heavy documents
Alternatives to Explore
If this approach fails or the DOCX structure differs:
- Check for
word/document.xmlexistence:unzip -l filename.docx | grep document.xml - Some documents may use
word/*.xmlwith different naming - Consider
pandocif available:pandoc filename.docx -t plain
よくある質問
なぜWordファイルがzipのように振る舞うのですか?
.docxファイルは、文書の内容を保持するXMLファイルを含むzipアーカイブだからです。
書式や表は残りますか?
この方法はマークアップを取り除くため、元のレイアウトではなくプレーンテキストを返します。
結果を保存できますか?
はい。抽出したテキストをテキストファイルに書き出す方法が示されています。
詳細
作者による元の説明
Extract text from DOCX files using shell commands when python-docx is unavailable
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #12867
- ライセンス
- MIT
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
agentpilot
7.8kエージェントが、作業を準備し、変更案を提案してテストし、評価するAgentPilotのループを実行することで、プロジェクトを段階的に改善できるよう支援します。
openspace
7.8kエージェントが、スキルを保存し取り出すツールであるOpenSpaceをセットアップし、MCPを通じてAIアプリに接続できるよう支援します。
rsi-arena
7.8kエージェントが、AIMEやTerminal-Benchなどの標準的なAIベンチマークテストをセットアップして実行し、異なる改善方法を比較できるよう支援します。
experiment-guide
7.8kエージェントが、プログラムを改善する方法を調べる間に、小さな実験を計画し、その結果を読み、発見を記録できるよう支援します。
似ているスキル
feishu-doc
394kテキスト、画像、表を含むFeishuのクラウドドキュメントを、ドキュメントツールを使って読み、作成し、編集するようエージェントを支援します。
feishu-drive
394kボットと共有されたFeishuのクラウドフォルダ内のファイルを閲覧、整理、コメントできるようエージェントを支援します。
feishu-perm
394kFeishuのファイルにアクセスできる人を確認し、変更するようエージェントを支援します。依頼を満たす最小の権限を選びます。