docx-dual-parse
Was er macht
Dieser Skill erklärt zwei Wege, Text aus einer .docx-Datei zu holen, und wie man zwischen ihnen wählt. Er richtet sich an Menschen, die auf Computern arbeiten, auf denen manche Werkzeuge fehlen.
Wann du ihn nutzt
- ✓Wenn ich Word-Text auf einem Computer lesen muss, auf dem Werkzeuge fehlen.
- ✓Wenn python-docx nicht installiert ist, Python aber verfügbar ist.
- ✓Wenn die üblichen Shell-Werkzeuge zum Entpacken eingeschränkt sind.
Link zum Skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/docx-shell-parse-enhanced-4bba79/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Bitte lies den Text aus meinem Word-Dokument. Wenn der übliche Befehl hier nicht funktioniert, nimm die andere Methode.”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Die KI prüft, ob unzip verfügbar ist, und nutzt dann die Shell-Extraktion. Andernfalls liest sie das ZIP-Archiv direkt mit Python und entfernt die Auszeichnung.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
DOCX Dual-Method Text Extraction
Extract text from Microsoft Word (.docx) files using either shell commands or Python's zipfile module, automatically selecting the most reliable method for your environment.
When to Use
- Need reliable DOCX text extraction in varying environments (containers, sandboxes, minimal images)
- Python environment may lack
python-docxbut has standard library access - Shell utilities (
unzip,sed) may be unavailable or restricted - Want environment-aware fallback without manual intervention
Core Technique
DOCX files are ZIP archives containing XML files. This skill provides two extraction methods:
Method A (Shell): unzip -p + sed for tag stripping
Method B (Python): zipfile module for archive access + string parsing
Environment Detection
Before extraction, detect which method will work:
# Quick shell method test
if unzip -v >/dev/null 2>&1; then
echo "Shell method available"
else
echo "Shell method unavailable, try Python"
fi
# Quick Python method test
python3 -c "import zipfile; print('Python method available')" 2>/dev/null
Method A: Shell-Based Extraction
Use when unzip and sed are available and the environment allows shell operations.
Step-by-Step Instructions
1. Verify the DOCX file exists
ls -la document.docx
2. Extract raw XML content
unzip -p document.docx word/document.xml
3. Strip XML tags from content
unzip -p document.docx word/document.xml | sed -e 's/<[^>]*>//g'
4. Clean up whitespace (optional)
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
Reusable Shell Function
parse_docx_shell() {
local file="$1"
if [ ! -f "$file" ]; then
echo "Error: File not found: $file" >&2
return 1
fi
if ! command -v unzip >/dev/null 2>&1; then
echo "Error: unzip not available" >&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_shell document.docx
Method B: Python Zipfile Extraction
Use when shell method fails or Python environment is more reliable than shell.
Step-by-Step Instructions
1. Verify the DOCX file exists
ls -la document.docx
2. Run Python extraction via run_shell
run_shell 'python3 -c "
import zipfile
import re
with zipfile.ZipFile(\"document.docx\", \"r\") as z:
content = z.read(\"word/document.xml\").decode(\"utf-8\")
text = re.sub(r\"<[^>]*>\", \"\", content)
lines = [l.strip() for l in text.splitlines() if l.strip()]
for line in lines:
print(line)
"'
3. Save to file by redirecting output
run_shell 'python3 -c "
import zipfile
import re
with zipfile.ZipFile(\"document.docx\", \"r\") as z:
content = z.read(\"word/document.xml\").decode(\"utf-8\")
text = re.sub(r\"<[^>]*>\", \"\", content)
lines = [l.strip() for l in text.splitlines() if l.strip()]
with open(\"output.txt\", \"w\") as f:
for line in lines:
f.write(line + \"\\n\")
"'
Reusable Python Function (via run_shell)
parse_docx_python() {
local file="$1"
local output="$2"
if [ ! -f "$file" ]; then
echo "Error: File not found: $file" >&2
return 1
fi
run_shell "python3 -c \"
import zipfile
import re
import sys
try:
with zipfile.ZipFile(\\'$file\\', \\'r\\') as z:
content = z.read(\\'word/document.xml\\').decode(\\'utf-8\\')
text = re.sub(r\\'<[^>]*>\\', \\'\\', content)
lines = [l.strip() for l in text.splitlines() if l.strip()]
for line in lines:
print(line)
except Exception as e:
print(f\\'Error: {e}\\', file=sys.stderr)
sys.exit(1)
\""
}
# Usage: parse_docx_python document.docx
# Or to file: parse_docx_python document.docx > output.txt
Unified Dual-Method Function
Automatically tries shell first, falls back to Python if shell fails:
parse_docx() {
local file="$1"
if [ ! -f "$file" ]; then
echo "Error: File not found: $file" >&2
return 1
fi
# Try shell
Häufige Fragen
Wie wählt er eine Methode?
Er führt zuerst einen kurzen Test des Shell-Werkzeugs aus und nutzt Python, wenn dieser Test fehlschlägt.
Wird das zipfile-Modul von Python benötigt?
Ja, die Python-Methode nutzt das zipfile-Modul aus der Standardbibliothek.
Braucht das python-docx?
Nein. Beide Methoden funktionieren ohne python-docx.
Details
Originalbeschreibung des Autors
Extract text from DOCX files using shell or Python zipfile, with environment-aware fallback
repo: HKUDS/AgentPilot
Beliebtheit
- GitHub-Sterne
- 7.8k
- Platz im Ranking
- #12868
- Lizenz
- MIT
- Aktualisiert
- 1.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
agentpilot
7.8kHilft deinem Agenten, ein Projekt Schritt für Schritt zu verbessern: Er bereitet eine Aufgabe vor und startet die AgentPilot-Schleife, die Änderungen testet und bewertet.
openspace
7.8kHilft deinem Agenten, OpenSpace einzurichten, ein Werkzeug, das Agenten-Skills speichert und abruft, und es über MCP mit deiner KI-App zu verbinden.
rsi-arena
7.8kHilft deinem Agenten, Standard-Benchmarks für KI wie AIME und Terminal-Bench einzurichten und auszuführen, um Verbesserungsmethoden zu vergleichen.
experiment-guide
7.8kHilft deinem Agenten, kleine Experimente zu planen, Ergebnisse auszuwerten und Erkenntnisse festzuhalten, während er ein Programm verbessern will.
Ähnliche Skills
feishu-doc
394kHilft deinem Agenten, Feishu-Cloud-Dokumente zu lesen, zu erstellen und zu bearbeiten, einschließlich Text, Bildern und Tabellen, über das Dokument-Werkzeug.
feishu-drive
394kLässt deinen Agenten Dateien in einem Feishu-Cloud-Ordner durchsehen, ordnen und kommentieren, der mit dem Bot geteilt wurde.
feishu-perm
394kHilft deinem Agenten zu prüfen und zu ändern, wer auf eine Feishu-Datei zugreifen darf, und wählt dabei die kleinste Berechtigung, die deine Anfrage erfüllt.