How to use sed to replace only the first occurrence in a file?

A sed script that will only replace the first occurrence of “Apple” by “Banana” Example Input: Output: Apple Banana Apple Apple Orange Orange Apple Apple This is the simple script: Editor’s note: works with GNU sed only. sed ‘0,/Apple/{s/Apple/Banana/}’ input_filename The first two parameters 0 and /Apple/ are the range specifier. The s/Apple/Banana/ is what … Read more