Skip to content
Skillpedia
PDF, Word & slides7.8k · #12870

docx-shell-parse

What it does

This skill shows the basic steps for reading .docx files with standard shell tools. It is for people who need quick text from Word files in limited setups.

When to use it

  • ✓When Python libraries for Word files are not installed on my computer.
  • ✓When I need quick text extraction without installing dependencies.
  • ✓When I am working in a container or minimal system with few tools.

Skill link

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

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/docx-shell-parse/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Get me the text of this Word document. I cannot install libraries here, so please use the shell.”

5 new skills a week. 1 minute to read.

How it works

The AI confirms the file exists, unzips the main document XML, removes the tags and blank lines, and can save the text to a file.

Technical content (original SKILL.md)

Original text by the author, straight from 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"
FAQ

Which part of the Word file holds the text?

The main content is in the word/document.xml file inside the archive.

Are blank lines removed?

The optional cleanup step removes extra whitespace and empty lines.

Can I save the result?

Yes, the guide shows how to write the extracted text to a text file.

Details

Original description by the author

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

repo: HKUDS/AgentPilot

Popularity

GitHub stars
7.8k
Ranking position
#12870
License
MIT
Updated
11/1/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills