0

I'm trying to match this pattern in grep that takes the form:

string.*char

But it doesn't match the char to the first occurrence.

Example:

command | grep -o '{id.*}'

The output of command is formatted something like:

*a lot of stuff I don't care about* {id: *comma sep. data*}, {*more data*}

I want it to output {id: *comma sep. data*} not {id: *comma sep. data*}, {*more data*}

1 Answers1

0

As @Barmar replied, .* is greedy

grep -o '{id[}^]*}'

or

grep -o -P '{id.*?}'

will work to make it lazy