sed 's/this/that/' -- ignoring g but still replace entire file

Posted by lakshmipathi on Stack Overflow See other posts from Stack Overflow or by lakshmipathi
Published on 2010-06-02T09:13:08Z Indexed on 2010/06/02 9:44 UTC
Read the original article Hit count: 167

Filed under:
|

as title said, Im trying to change only the first occurrence of word.By using sed 's/this/that/' file.txt

though i'm not using g option it replace entire file. How to fix this.?

UPDATE:

$ cat file.txt 
  first line
  this 
  this 
  this
  this
$ sed -e '1s/this/that/;t' file.txt 
  first line
  this  // ------> I want to change only this "this" to "that" :)
  this 
  this
  this

© Stack Overflow or respective owner

Related posts about shell

Related posts about sed