Tóth Attila
Tóth Attila

Reputation: 149

Capturing matches with sed

I have just started experimenting with sed and don't really get how does match capturing work: if I have a code like this for capturing two words sed 's/\([a-z]*\).*\([a-z]*\).*/\1 \2/' why isn't the second word captured?

Edit1: Let's say I have this string: "the brown fox jumps over the lazy dog". I want sed to match "the brown", but it only matches the first word

Upvotes: 0

Views: 167

Answers (1)

Yunnosch
Yunnosch

Reputation: 26703

(Quoting Sundeep, just to make a Q/A pair.)

replace the dot in .* with space character...

sed 's/\([a-z]*\) *\([a-z]*\).*/\1 \2/'

Upvotes: 1

Related Questions