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

docx-shell-extract

What it does

This skill shows how to read a .docx file by unzipping it and removing its markup with standard command-line tools. It is for people who need Word text without installing extra software.

When to use it

  • ✓When python-docx or similar libraries are not available on my computer.
  • ✓When I need a quick text extract from a Word file without installing anything.
  • ✓When the environment is restricted and only shell tools work.

Skill link

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/docx-shell-extract/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-extract/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

“I need the text from this Word file, and I cannot install any extra software. Can you pull it out using the command line?”

5 new skills a week. 1 minute to read.

How it works

A .docx file is a zip archive with XML inside. The AI extracts the main document XML, removes the tags and blank lines, and saves the result as plain text.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

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

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

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:

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)

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

Complete Example

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

# 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

Limitations

  • This method extracts raw text without formatting
  • Complex layouts, tables, and images are not preserved
  • Some special characters may need additional handling
  • Works best for text-heavy documents

Alternatives to Explore

If this approach fails or the DOCX structure differs:

  • Check for word/document.xml existence: unzip -l filename.docx | grep document.xml
  • Some documents may use word/*.xml with different naming
  • Consider pandoc if available: pandoc filename.docx -t plain
FAQ

Why does a Word file act like a zip?

A .docx file is a zip archive that contains XML files holding the document content.

Are formatting and tables kept?

The method strips the markup, so it returns plain text and not the original layout.

Can the output be saved?

Yes, the guide shows how to write the extracted text to a 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
#12867
License
MIT
Updated
11/1/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills