求一个shell脚本删除文本中指定行

我有一个文本文档记录了很多deb软件包的信息,给个例子:Package:2vcardPriority:optionalSection:utilsInstalled-Siz... 我有一个文本文档记录了很多deb软件包的信息,给个例子:
Package: 2vcard
Priority: optional
Section: utils
Installed-Size: 108
Maintainer: Martin Albisetti <argentina@gmail.com>
Architecture: all
Version: 0.5-3
Filename: pool/main/2/2vcard/2vcard_0.5-3_all.deb
Size: 14300
MD5sum: d831fd82a8605e9258b2314a7d703abe
SHA1: e903a05f168a825ff84c87326898a182635f8175
SHA256: 2be9a86f0ec99b1299880c6bf0f4da8257c74a61341c14c103b70c9ec04b10ec
Description: perl script to convert an addressbook to VCARD file format
2vcard is a little perl script that you can use to convert the
popular vcard file format. Currently 2vcard can only convert addressbooks
and alias files from the following formats: abook,eudora,juno,ldif,mutt,
mh and pine.
.
The VCARD format is used by gnomecard, for example, which is used by the
balsa email client.
Tag: implemented-in::perl, role::program, use::converting

现在我想保留以“Pre-depends:"或"Depends:"或"Filename:"开头的信息,把其他的都过滤掉。怎么实现??
展开
 我来答
徐未知
2012-05-21 · TA获得超过226个赞
知道小有建树答主
回答量:201
采纳率:100%
帮助的人:202万
展开全部
grep就ok了,加上-E参数:
示例:
bsstest2:/billing/app/user/xufc/test$grep -E "^Pre-depends:|^Depends:|^Filename:" info.txt
Filename: pool/main/2/2vcard/2vcard_0.5-3_all.deb
你给的文件中只有一个Filename开头的,所以只有一个结果
下面我换个搜索条件,显示可能会更加清晰:
bsstest2:/billing/app/user/xufc/test$grep -E "^Section:|^Version:|^Filename:" info.txt
Section: utils
Version: 0.5-3
Filename: pool/main/2/2vcard/2vcard_0.5-3_all.deb
bsstest2:/billing/app/user/xufc/test$
其中info.txt就是你给的示例文件
lottolotto
2012-05-21 · TA获得超过725个赞
知道小有建树答主
回答量:737
采纳率:0%
帮助的人:272万
展开全部
cat text |egrep -i "^Depends|^Filename:|^Pre-depends:" >> mynewfile
实例如下:

[lotto@ftptest2 ~]$ cat text
Package: 2vcard
Priority: optional
Section: utils
Installed-Size: 108
Maintainer: Martin Albisetti <argentina@gmail.com>
Architecture: all
Version: 0.5-3
Filename: pool/main/2/2vcard/2vcard_0.5-3_all.deb
Size: 14300
MD5sum: d831fd82a8605e9258b2314a7d703abe
SHA1: e903a05f168a825ff84c87326898a182635f8175
SHA256: 2be9a86f0ec99b1299880c6bf0f4da8257c74a61341c14c103b70c9ec04b10ec
Description: perl script to convert an addressbook to VCARD file format
2vcard is a little perl script that you can use to convert the
popular vcard file format. Currently 2vcard can only convert addressbooks
and alias files from the following formats: abook,eudora,juno,ldif,mutt,
mh and pine.
.
The VCARD format is used by gnomecard, for example, which is used by the
balsa email client.
Tag: implemented-in::perl, role::program, use::converting
[lotto@ftptest2 ~]$ cat text |egrep -i "^Depends|^Filename:|^Pre-depends:" >> mynewfile
[lotto@ftptest2 ~]$ cat mynewfile
Filename: pool/main/2/2vcard/2vcard_0.5-3_all.deb
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式