gawk - replace first occurrence of text using awk -


the code below replaces first occurrence of apple banana. how achieve same using awk / gawk?

sed -i "0,/apple/s//banana/" myfile.txt 

this come with:

awk '!x{x=sub("apple","banana")}7' file 

for example:

kent$  cat f foo apple foo apple apple  kent$  awk '!x{x=sub("apple","banana")}7' f foo banana foo apple apple 

for sed -i (change in place) part, if use gawk 4.1.0, have option too. otherwise, have use temp file.


Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -