# DOCX Shell Extract

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

- 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-shell-extract -g -a claude-code -y`
Codex: `npx skills add HKUDS/AgentPilot --skill docx-shell-extract -g -a codex -y`
Cursor: `npx skills add HKUDS/AgentPilot --skill docx-shell-extract -g -a cursor -y`
Gemini CLI: `npx skills add HKUDS/AgentPilot --skill docx-shell-extract -g -a gemini-cli -y`

## Description

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

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

# 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-docx` library 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

```bash
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

```bash
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:

```bash
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 `&amp;`, `&lt;`)
- Leading/trailing whitespace
- Empty lines

### Step 4: Save to a text file (optional)

```bash
unzip -p filename.docx word/document.xml | \
  sed 's/<[^>]*>//g' > output.txt
```

## Complete Example

```bash
# 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:

```bash
# 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
```

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