求一个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:"开头的信息,把其他的都过滤掉。怎么实现?? 展开
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:"开头的信息,把其他的都过滤掉。怎么实现?? 展开
2个回答
展开全部
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就是你给的示例文件
示例:
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就是你给的示例文件
展开全部
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
实例如下:
[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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询