0

I have a text file like this:

OBJ O1 = {
{P11},
{0}
};

OBJ O2 = {
{P21},
{P22},
{P23},
{0}
};

OBJ O3 = {
{P31},
{P32},
{0}
};

I want to print only lines starting by OBJ O2 and ending by first {0} after OBJ O2

OBJ O2 = {
{P21},
{P22},
{P23},
{0}
};

Is there a solution to print these lines using cat, sed, awk or grep?

Nesrine_Kh
  • 17
  • 3

2 Answers2

1

You can do this :

awk '/OBJ O2/,/^};$/' file
Corentin Limier
  • 4,946
  • 1
  • 13
  • 24
0

An awk alternative (without range expression), cf. Is a /start/,/end/ range expression ever useful in awk?

awk '/^OBJ O2/{f=1} f{print; if(/};/) f=0}' file
Thomas Hansen
  • 775
  • 1
  • 6
  • 17