한문장에서 특정단어가 2번이상 반복될때, 첫번째로 나오는 특정단어만 치환하려면 어떻게 해야 합니까?

k1d0bus3의 이미지

예를 들어 수백개의 파일에 다음과 같은 문장이 들어 있습니다.
There is a Apple, and the Apple is red.
이때 첫번째로 나오는 Apple만 Banana로 바꾸려면 어떻게 해야 합니까?

chanik의 이미지

sed를 쓴다고 할 때, s 명령의 기본 행동이 첫 번째 매치만 치환하는 것입니다.

$ echo "There is a Apple, and the Apple is red." | sed -e "s/Apple/Banana/"
There is a Banana, and the Apple is red.

참고로 이런 행동방식을 바꾸려면 아래와 같이 뒤에 한정자(modifier)를 붙이면 됩니다.
n번째 매치만 치환한다든지, 전부 치환한다든지 하는 식으로요.

$ echo "There is a Apple, and the Apple is red." | sed -e "s/Apple/Banana/1"
There is a Banana, and the Apple is red.
$ echo "There is a Apple, and the Apple is red." | sed -e "s/Apple/Banana/2"
There is a Apple, and the Banana is red.
$ echo "There is a Apple, and the Apple is red." | sed -e "s/Apple/Banana/g"
There is a Banana, and the Banana is red.