ed에서 두 번째로 나타나는 단어/구문을 바꿉니다.

ed에서 두 번째로 나타나는 단어/구문을 바꿉니다.

ed에서 두 번째/세 번째 단어/구문만 바꾸는 구문은 무엇입니까?

He wanted to buy groceries from the shop, but preferred not having to go into the shop. >>
He wanted to buy groceries from the shop, but preferred not having to go into it. >>

답변1

ed, 의 대체 명령은 s///명령 문자열 끝에 0개 이상의 플래그를 사용합니다. 플래그에 양의 정수가 포함된 경우N, 대체가 적용됩니다.N: 첫 번째 게임.

the shop현재 줄에서 두 번째로 나타나는 하위 문자열을 string 으로 바꾸고 싶다고 가정하면 it다음을 사용할 수 있습니다.

s/the shop/it/2

편집 세션의 스냅샷은 다음과 같을 수 있습니다. 여기서 사용자는 현재 행을 본 p다음 두 번째 항목을 변경하기로 결정하고 the shop편집 후 행을 다시 표시합니다(다음을 사용).p 배너명령 s///):

p
He wanted to buy groceries from the shop, but preferred not having to go into the shop.
s/the shop/it/2p
He wanted to buy groceries from the shop, but preferred not having to go into it.

편집 명령의 이 기능은 s///상속됩니다 sed.

관련 정보