How to replace the second occurrence of the word “bat” with “ball” in a file?

sed ‘s/bat/ball/2’ < filename

Category: UNIX Interview Questions.