Arjun
Arjun

Reputation: 465

Linux script for matching a multi-line statement

How can I write a fast shell script to match the following in linux. I have tried various combinations of grep commands, sed commands but no success. The "message" section can be repeated any number of times. The contents of the "message" itself will be generic but fixed to the format shown below. I want the output to be something like:

x: y
x1: y1
x: y
x1: y1
x: y
x1: y1

Input:

Posting to abcd
message {
 a {
     x : y
     x1 : y1
   }
}
message {
 a {
     x : y
     x1 : y1
   }
}
message {
 a {
     x : y
     x1 : y1
   }
}

Upvotes: 0

Views: 105

Answers (1)

potong
potong

Reputation: 58391

This might work for you (GNU sed):

sed '/^message {/,/^}/{/[{}]/d;s/^\s*//}' file

Within the block message { to }, delete any lines containing a { or a } and then remove any white space from the start of any subsequent line.

Upvotes: 1

Related Questions