bash Sed:获取以一些前缀开头的行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13202715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 22:54:34  来源:igfitidea点击:

Sed: get lines beginning with some prefix

bashsedawk

提问by CAMOBAP

I have file Blackberry jad file:

我有文件 Blackberry jad 文件:

RIM-COD-URL-12: HelloWorld-12.cod
RIM-COD-Size: 68020
RIM-MIDlet-Icon-2-1: ____HOVER_ICON_res/icon/blackberry/icon-68.png,focused
RIM-COD-URL-11: HelloWorld-11.cod
RIM-MIDlet-Icon-Count-2: 1
RIM-COD-URL-10: HelloWorld-10.cod
RIM-MIDlet-Icon-Count-1: 1
MIDlet-Vendor: Vasia Pupkin
RIM-MIDlet-Icon-1-1: res\icon\blackberry\____HOVER_ICON_icon-68.png,focused
Manifest-Version: 1.0
RIM-MIDlet-Flags-1: 0
RIM-COD-SHA1-38: 9a c8 b3 35 72 de 34 5e 7a 0a 5b 9e c3 3a 65 4c 20 0f 8e 50

I just want to get lines begin with RIM-COD-.

我只想让行以RIM-COD-.

Can you provide me solutions for awkor sed?

你能为我提供了解决方案,awksed

回答by John3136

Use sed -nand only print lines that match RIM-COD.

使用sed -n且仅打印与 RIM-COD 匹配的行。

sed -n -e '/^RIM-COD-/p' yourfile.txt

回答by Gilles Quenot

Try doing this :

尝试这样做:

awk '/^RIM-COD/' file.txt

Or

或者

grep "^RIM-COD" file.txt

Or

或者

sed -n '/^RIM-COD/p' file.txt