Zum Inhalt springen
Skillpedia
PDF, Word & Folien7.8k · #12870

docx-shell-parse

Was er macht

Dieser Skill zeigt die Grundschritte, .docx-Dateien mit Standard-Shell-Werkzeugen zu lesen. Er richtet sich an Menschen, die in eingeschränkten Umgebungen schnell Text aus Word-Dateien brauchen.

Wann du ihn nutzt

  • ✓Wenn Python-Bibliotheken für Word-Dateien auf meinem Computer nicht installiert sind.
  • ✓Wenn ich schnell Text extrahieren möchte, ohne Abhängigkeiten zu installieren.
  • ✓Wenn ich in einem Container oder einem minimalen System mit wenigen Werkzeugen arbeite.

Link zum Skill

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/docx-shell-parse/SKILL.md

Kopiere 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

Nutze diesen Skill, um mir zu helfen: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/docx-shell-parse/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Hol mir den Text dieses Word-Dokuments. Ich kann hier keine Bibliotheken installieren, also nutze bitte die Shell.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Die KI prüft, ob die Datei existiert, entpackt das Haupt-XML-Dokument, entfernt die Tags und Leerzeilen und kann den Text in eine Datei speichern.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von 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-docx or 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"
Häufige Fragen

Wo steckt der Text in der Word-Datei?

Der Hauptinhalt liegt in der Datei word/document.xml innerhalb des Archivs.

Werden Leerzeilen entfernt?

Der optionale Bereinigungsschritt entfernt überflüssige Leerzeichen und leere Zeilen.

Kann ich das Ergebnis speichern?

Ja. Die Anleitung zeigt, wie der extrahierte Text in eine Textdatei geschrieben wird.

Details

Originalbeschreibung des Autors

Extract text from DOCX files using shell commands when python-docx is unavailable

repo: HKUDS/AgentPilot

Beliebtheit

GitHub-Sterne
7.8k
Platz im Ranking
#12870
Lizenz
MIT
Aktualisiert
1.11.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills