sed删除多行的问题

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

sed删除多行的问题

#1

帖子 百草谷居士 » 2015-09-24 14:49

下面是wps关于mime类型的定义文件
<?xml version='1.0' encoding='utf-8'?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/wps-office.xls">
<comment>Microsoft Excel Spreadsheet</comment>
<comment xml:lang="en">Microsoft Excel Spreadsheet</comment>
<comment xml:lang="zh_CN">Microsoft Excel 工作表</comment>
<alias type="application/vnd.ms-excel"/>
<alias type="application/msexcel"/>
<alias type="application/x-msexcel"/>
<alias type="application/vnd.ms-excel.sheet.macroenabled.12"/>
<generic-icon name="wps-office-xls"/>
<glob pattern="*.xls" weight="60"/>
<glob pattern="*.xlsm" weight="60"/>
</mime-type>
<mime-type type="application/wps-office.xlt">
<comment>Microsoft Excel Template</comment>
<comment xml:lang="zh_CN">Microsoft Excel 模板</comment>
<alias type="application/vnd.ms-excel.template.macroenabled.12"/>
<sub-class-of type="application/vnd.ms-excel"/>
<generic-icon name="wps-office-xlt"/>
<glob pattern="*.xlt" weight="60"/>
<glob pattern="*.xltm" weight="60"/>
</mime-type>
<mime-type type="application/wps-office.xltx">
<comment>Microsoft Excel Template</comment>
<comment xml:lang="zh_CN">Microsoft Excel 模板</comment>
<alias type="application/vnd.openxmlformats-officedocument.spreadsheetml.template"/>
<generic-icon name="wps-office-xlt"/>
<glob pattern="*.xltx" weight="60"/>
</mime-type>
<mime-type type="application/wps-office.xlsx">
<comment>Microsoft Excel Spreadsheet</comment>
<comment xml:lang="zh_CN">Microsoft Excel 工作表</comment>
<alias type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>
<generic-icon name="wps-office-xls"/>
<glob pattern="*.xlsx" weight="60"/>
</mime-type>
<mime-type type="application/wps-office.et">
<comment>WPS Spreadsheets Workbook</comment>
<comment xml:lang="zh_CN">WPS表格 工作簿</comment>
<generic-icon name="wps-office-et"/>
<glob pattern="*.et" weight="60"/>
</mime-type>
<mime-type type="application/wps-office.ett">
<comment>WPS Spreadsheets Template</comment>
<comment xml:lang="zh_CN">WPS表格 模板</comment>
<generic-icon name="wps-office-ett"/>
<glob pattern="*.ett" weight="60"/>
</mime-type>
</mime-info>
问题:
想要删除<mime-type type="application/wps-office.xls">小节,<mime-type type="application/wps-office.xlt">小节,<mime-type type="application/wps-office.xltx">小节,<mime-type type="application/wps-office.xlsx">小节。
如何使用sed进行处理?
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: sed删除多行的问题

#2

帖子 vickycq » 2015-09-24 15:59

代码: 全选

sed -i '/<mime-type type="application\/wps-office.xls">/,/<\/mime-type>/d' test.xml
sed -i '/<mime-type type="application\/wps-office.xlt">/,/<\/mime-type>/d' test.xml
sed -i '/<mime-type type="application\/wps-office.xltx">/,/<\/mime-type>/d' test.xml
sed -i '/<mime-type type="application\/wps-office.xlsx">/,/<\/mime-type>/d' test.xml
参考
http://stackoverflow.com/questions/6945 ... ck-of-text
http://www.linuxtopia.org/online_books/ ... 4_013.html
上次由 vickycq 在 2015-09-24 16:03,总共编辑 1 次。
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

Re: sed删除多行的问题

#3

帖子 百草谷居士 » 2015-09-24 16:03

代码: 全选

sed -i '/<mime-type type="application\/wps-office.xl[st]x*">/,/<\/mime-type>/d'  wps-office-et.xml
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
回复