Перейти к содержанию
Skillpedia
PDF, Word и слайды7.8k · #12867

docx-shell-extract

Что он делает

Этот скилл показывает, как прочитать файл .docx: распаковать его и удалить разметку стандартными инструментами командной строки. Он нужен тем, кому требуется текст из Word без установки дополнительного ПО.

Когда использовать

  • ✓Когда библиотеки python-docx или похожие недоступны на моём компьютере.
  • ✓Когда нужен быстрый текст из файла Word и ничего устанавливать не хочется.
  • ✓Когда среда ограничена и работают только инструменты оболочки.

Ссылка на скилл

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

Скопируйте и вставьте её в ваш ИИ (Claude, ChatGPT или Cursor) с просьбой следовать инструкциям.

Как использовать

Самый простой способ: скопируйте сообщение и вставьте его в свой ИИ. Он прочитает скилл и выполнит инструкции.

Готовое сообщение для вставки

Используй этот скилл, чтобы помочь мне: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/docx-shell-extract/SKILL.md Прочитай файл SKILL.md по этой ссылке и следуй его инструкциям в моей задаче.
Хотите, чтобы ваш ИИ сам находил такие скиллы?Установите бесплатный MCP Skillpedia: одна строка, и перед каждой задачей он ищет среди 15 000+ скиллов.Установить за 1 минуту →

Пример запроса к вашему ИИ

“Мне нужен текст из этого файла Word, а ставить дополнительное ПО нельзя. Вытащи его через командную строку.”

5 новых скиллов в неделю. 1 минута чтения.

Как это работает

Файл .docx — это zip-архив с XML внутри. ИИ извлекает основной XML документа, удаляет теги и пустые строки и сохраняет результат как простой текст.

Технический текст (оригинальный SKILL.md)

Оригинальный текст автора на английском, прямо с 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
Частые вопросы

Почему файл Word ведёт себя как zip?

Файл .docx — это zip-архив, внутри которого лежат XML-файлы с содержимым документа.

Сохраняются ли форматирование и таблицы?

Метод удаляет разметку, поэтому возвращается простой текст, а не исходная верстка.

Можно ли сохранить результат?

Да, руководство показывает, как записать извлечённый текст в файл.

Подробности

Оригинальное описание автора

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

repo: HKUDS/AgentPilot

Популярность

Звёзды на GitHub
7.8k
Место в рейтинге
#12867
Лицензия
MIT
Обновлён
01.11.2026

Полезен ли этот скилл?

0

Войдите , чтобы голосовать.

Комментарии

  • …

Другие скиллы из этого репозитория

Похожие скиллы