Eu tenho o seguinte texto no arquivo sentença.txt
Linux refers to the family of Unix-like computer operating systems
that use the Linux kernel.
Linux can be installed on a wide variety of computer hardware, ranging
from mobile phones, tablet computers and video game consoles, to
mainframes and supercomputers. Linux is
predominantly known for its use in servers.
It has a server market share ranging between 20–40%.
Most desktop computers run either Microsoft Windows or Mac OS X, with
Linux having anywhere from a low of an estimated 1–2% of the desktop
market to a high of an estimated 4. 8%.
However, desktop use of Linux has become increasingly popular in
recent years, partly owing to the popular Ubuntu, Fedora, Mint, and
openSUSE distributions and the emergence of netbooks and smart phones
running an embedded Linux.
Linux can be installed on a wide variety of computer hardware, ranging
from mobile phones, tablet computers and video game consoles, to
mainframes and supercomputers.
Neste texto, duas frases repetidas. É a última frase. Na verdade, eu apenas copiei e colei a segunda sentença no final do texto para ter duas ocorrências do mobile phones
~$ grep mobile sentence.txt
Linux can be installed on a wide variety of computer hardware, ranging from mobile phones, tablet computers and video game consoles, to mainframes and supercomputers.
Linux can be installed on a wide variety of computer hardware, ranging from mobile phones, tablet computers and video game consoles, to mainframes and supercomputers.
Então, eu queria saber qual ocorrência seria excluída pelo seguinte regex:
[^.]*mobile phones[^.]*\.
Eu acredito que a última ocorrência deve ser removida devido ao rastreamento de volta. Para verificar essa suposição e meu entendimento, apliquei o seguinte:
:~$ sed 's/[^.]*mobile phones[^.]*\.//' sentence.txt > sentence2.txt
Observe que eu não usei g
para substituir a primeira ocorrência encontrada (acho que seria a última frase).
Mas vejo que ambos são removidos!
~$ grep mobile sentence2.txt
~$
O que estou fazendo de errado aqui? 1) Meu entendimento do regex é que a última sentença seria a primeira errada? 2) Por que ambas as sentenças são removidas sem g
?