Extract text from DOCX files using shell commands when python-docx is unavailable
67
80%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./benchmarks/gdpval/skills/docx-shell-extract/SKILL.mdUse this pattern when you need to read or extract text from Microsoft Word (.docx) files in constrained environments where:
python-docx library is not availableDOCX 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.
unzip -p filename.docx word/document.xmlThe -p flag pipes the content to stdout without extracting to disk.
unzip -p filename.docx word/document.xml | sed 's/<[^>]*>//g'This removes all XML tags, leaving the text content.
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:
&, <)unzip -p filename.docx word/document.xml | \
sed 's/<[^>]*>//g' > output.txt# 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"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"
fiIf this approach fails or the DOCX structure differs:
word/document.xml existence: unzip -l filename.docx | grep document.xmlword/*.xml with different namingpandoc if available: pandoc filename.docx -t plainc5a9c4b
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.