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 في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“أحتاج إلى نص ملف Word هذا، ولا أستطيع تثبيت أي برنامج إضافي. هل تستطيع استخراجه باستخدام سطر الأوامر؟”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

ملف .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
آخر تحديث
1‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة