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
Post a Comment