Search and replace global modifier
Posted
by
mrucci
on Super User
See other posts from Super User
or by mrucci
Published on 2011-01-16T18:50:01Z
Indexed on
2011/01/16
18:55 UTC
Read the original article
Hit count: 322
Is there any reason why non-global/first-occurrence substitution is the default in many text editing programs (vim, sed, perl, etc.)?
I am talking about the /g
flag of search and replace commands like:
:s/pan/focaccia/g # in vim
sed 's/sfortuna/fortuna/g' # with sed
that will substitute every occurrence of the search pattern with the replacement string.
After (not too) many years of vim and sed usage I still did not find any use case for non-global substitutions. Is there some valid historical reason? Or it is because it is?
Thanks.
© Super User or respective owner