# DOCX Dual Parse

Extract text from DOCX files using shell or Python zipfile, with environment-aware...

- Repository: https://github.com/HKUDS/AgentPilot (7784 stars)
- Category: Documents
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add HKUDS/AgentPilot --skill docx-dual-parse -g -a claude-code -y`
Codex: `npx skills add HKUDS/AgentPilot --skill docx-dual-parse -g -a codex -y`
Cursor: `npx skills add HKUDS/AgentPilot --skill docx-dual-parse -g -a cursor -y`
Gemini CLI: `npx skills add HKUDS/AgentPilot --skill docx-dual-parse -g -a gemini-cli -y`

## Description

Extract text from DOCX files using shell or Python zipfile, with environment-aware fallback

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# 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-docx` but 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:

```bash
# Quick shell method test
if unzip -v >/dev/null 2>&1; then
    echo "Shell method available"
else
    echo "Shell method unavailable, try Python"
fi
```

```python
# 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**
```bash
ls -la document.docx
```

**2. Extract raw XML content**
```bash
unzip -p document.docx word/document.xml
```

**3. Strip XML tags from content**
```bash
unzip -p document.docx word/document.xml | sed -e 's/<[^>]*>//g'
```

**4. Clean up whitespace (optional)**
```bash
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**
```bash
unzip -p document.docx word/document.xml | \
  sed -e 's/<[^>]*>//g' > output.txt
```

### Reusable Shell Function

The rest: https://github.com/HKUDS/AgentPilot/blob/HEAD/openspace/benchmarks/gdpval/skills/docx-shell-parse-enhanced-4bba79/SKILL.md
