user642318
user642318

Reputation: 417

grep a left parenthesis

I have the following content below in a file:

text

(
      gab "test"
      set("TEST_SUB")
      origin(354 504)
      localize "T"
)

I have use vim /text \n[\t].\n[\t] and the "text" word and the left parentheses was highlighted.

But when I use egrep 'text \n[\t].\n[\t]' there is NO output. Just wondering how can I grep until the right parentheses.

Thank you.

Upvotes: 1

Views: 1344

Answers (2)

Dan
Dan

Reputation: 3594

Instead of egrep you can use sed.

sed -n '/^text/,/^($/p' yourfile will print all lines starting from where text is found until the ( is found at the beginning of a line.

Upvotes: 2

amccormack
amccormack

Reputation: 13927

If you know how long the sample is going to be, you can use the After flag, using -AN where N is the number of lines after the match you want to grab.

$grep -A7 "text" file.txt
text

(
      gab "test"
      set("TEST_SUB")
      origin(354 504)
      localize "T"
)

Upvotes: 0

Related Questions