Skip to main content

docx-shell-extract

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

소스 정보

저장소
HKUDS/OpenSpace
최근 소스 활동
2026년 7월 17일 03:43
감지된 SKILL.md 언어
영어
스타
7,753
포크
925

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

파일 탐색기
2 개 파일

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
docx-shell-extract
description
Extract text from DOCX files using shell commands when python-docx is unavailable
# 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 ``` ## 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`
GitHub에서 보기