Article 5KN2A sed command without global still changes all instances. Why is that?

sed command without global still changes all instances. Why is that?

by
crusader7
from LinuxQuestions.org on (#5KN2A)
Hey Guys,

I am uncertain why the sed command changes all instances without the "g" option. I am not sure why it is doing that. Any suggestions?

Here are the details...
My simple test_file contains the following text:
Quote:
Unix is great
unix will rule the world
I like unix
linux is better than windows
Windows is closed source while unix is open source
Then I run the following sed command:
Code:sed 's/unix/Linux/' test_fileHere are the results:
Quote:
Unix is great
Linux will rule the world
I like Linux
linux is better than windows
Windows is closed source while Linux is open source

The second line in my test_file gets changed from "unix" to "Linux". That is correct!
Without the "g" option (global), only the first occurrence should change. However each occurrence of unix gets changed. Why is that?latest?d=yIl2AUoC8zA latest?i=foxqaRk_iy0:VmWLi5M8gG0:F7zBnMy latest?i=foxqaRk_iy0:VmWLi5M8gG0:V_sGLiP latest?d=qj6IDK7rITs latest?i=foxqaRk_iy0:VmWLi5M8gG0:gIN9vFwfoxqaRk_iy0
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments