sed - Only replace a string only once in the entire file -


i have file wish replace string once in entire file ie first match finds should replaced. sed -i 's/foo/foo1/1'

try following:

sed -i '0,/foo/s//foo1/' file 

here,

/foo/ fetch line number of first occurrence of foo, let's #n

then same word searched till line #n , replaced foo1


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -