suggest I have a file example
as follows:
c
a
b
a
b
d
and I want to change the first occurance of a
to e
. Then I do this:
sed -i 's/a/e/' example
and all a
changed to e
.
So is there any way to make sed only replace once within a file?
Thanks.
Applying the information from Aziz' duplicate link to your question, I think this will give you the desired result for your case:
sed -i '0,/a/s//e/' example
Applying the information from Aziz' duplicate link to your question, I think this will give you the desired result for your case:
sed -i '0,/a/s//e/' example
Rabe's answer is good. But, adding a space between address range and 's' command makes it more clearer. like this:
sed -i '0,/a/ s//e/' example
And Wilson's version seems redundant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With