^word^replacement^ on all matches in Bash?

pisswillis picture pisswillis · Mar 16, 2009 · Viewed 10.9k times · Source

To clarify, I am looking for a way to perform a global search and replace on the previous command used. ^word^replacement^ only seems to replace the first match.

Is there some set option that is eluding me?

Answer

John Feminella picture John Feminella · Mar 16, 2009

Try this:

$ echo oneone
oneone
$ !!:gs/one/two/    # Repeats last command; substitutes 'one' --> 'two'.
twotwo