美文网首页
从docx文件中提取纯文本

从docx文件中提取纯文本

作者: 已不再更新_转移到qiita | 来源:发表于2019-11-28 00:30 被阅读0次

解压docx文件

直接使用unzip file.docs 命令,解压出来很多文件

├── [Content_Types].xml
├── _rels
├── docProps
│   ├── app.xml
│   └── core.xml
└── word
    ├── _rels
    │   └── document.xml.rels
    ├── document.xml
    └── settings.xml

查看下 word/document.xml的内容,非常标准的xml格式的文件

提取 xml中的纯文本

cat word/document.xml sed -e 's/<[^>]\{1,\}>//g; s/[^[:print:]]\{1,\}//g'

组合命如下, unzip -p 是解压文件到管道流,而不是输出文件。

unzip -p file.docx word/document.xml | sed -e 's/<[^>]\{1,\}>//g; s/[^[:print:]]\{1,\}//g'

参考:

https://www.commandlinefu.com/commands/view/4311/extract-plain-text-from-ms-word-docx-files

相关文章

网友评论

      本文标题:从docx文件中提取纯文本

      本文链接:https://www.haomeiwen.com/subject/xaxpwctx.html