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:
Then I run the following sed command:
Code:sed 's/unix/Linux/' test_fileHere are the results:
Quote:
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?
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 |
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?