The number where you have it currently will at the line it is on and only replace the n'th item, so if you have a line:
and use your first example you would get:
Code:
$ sed 's/apple/banana/1' fruit_file
banana pear apple
$ sed 's/apple/banana/2' fruit_file
apple pear banana
So the numbers relate to position on the line.
You want your script to stop after it makes the necessary change, so I would use:
Code:
sed '/apple/{s/apple/banana/1;q}' file
One of the gurus may have a way to shorten that, but it should work till then
