Salah Eddine Taouririt
Salah Eddine Taouririt

Reputation: 26415

How sed 's/pattern/substitution/2g' really work?

Why echo 'word word word word word word' | sed 's/[a-zA-Z]* /DELETED /2g'

prints word DELETED DELETED DELETED DELETED word ?

Why sed didn't substitute the last word ?

Upvotes: 0

Views: 694

Answers (1)

RichieHindle
RichieHindle

Reputation: 281505

Because your regular expression has a trailing space:

/[a-zA-Z]* /
          ^

It's explicitly searching for zero or more letters followed by a space.

Upvotes: 4

Related Questions