Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sed: get lines beginning with some prefix

Tags:

bash

sed

awk

I have file Blackberry jad file:

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-.

Can you provide me solutions for awk or sed?

like image 622
CAMOBAP Avatar asked Nov 02 '12 20:11

CAMOBAP


People also ask

What is $P in sed?

In sed, p prints the addressed line(s), while P prints only the first part (up to a newline character \n ) of the addressed line. If you have only one line in the buffer, p and P are the same thing, but logically p should be used.

How do you insert a line break in sed?

The "a" command to sed tells it to add a new line after a match is found. The sed command can add a new line before a pattern match is found. The "i" command to sed tells it to add a new line before a match is found.

How do you add a string at the beginning of each line in Linux?

The sed command can be used to add any character of your choosing to the beginning of each line. This is the same whether you are adding a character to each line of a text file or standard input.


2 Answers

Use sed -n and only print lines that match RIM-COD.

sed -n -e '/^RIM-COD-/p' yourfile.txt 
like image 133
John3136 Avatar answered Sep 25 '22 05:09

John3136


Try doing this :

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

Or

grep "^RIM-COD" file.txt 

Or

sed -n '/^RIM-COD/p' file.txt 
like image 39
Gilles Quenot Avatar answered Sep 25 '22 05:09

Gilles Quenot