sed 4.4는 어떤 구분 기호를 지원합니까?

sed 4.4는 어떤 구분 기호를 지원합니까?

나는 이 두 sed 명령이 동일할 것으로 예상했지만 mozilla/DST_Root_CA_X3.crt두 번째 경우에만 제거됩니다. 이유는 무엇입니까?

중요한 경우 sed 4.4와 Debian Stretch를 사용하고 있습니다.

(stretch-arm64)ubuntu@ip-10-1-2-224:~$ sudo sed '#^mozilla/DST_Root_CA_X3.crt$#d' test-certificates.conf
mozilla/Verisign_Class_3_Public_Primary_Certification_Authority_-_G3.crt
mozilla/XRamp_Global_CA_Root.crt
mozilla/certSIGN_ROOT_CA.crt
mozilla/ePKI_Root_Certification_Authority.crt
mozilla/emSign_ECC_Root_CA_-_C3.crt
mozilla/emSign_ECC_Root_CA_-_G3.crt
mozilla/emSign_Root_CA_-_C1.crt
mozilla/emSign_Root_CA_-_G1.crt
mozilla/DST_Root_CA_X3.crt

(stretch-arm64)ubuntu@ip-10-1-2-224:~$ sudo sed '/^mozilla\/DST_Root_CA_X3.crt$/d' test-certificates.conf
mozilla/Verisign_Class_3_Public_Primary_Certification_Authority_-_G3.crt
mozilla/XRamp_Global_CA_Root.crt
mozilla/certSIGN_ROOT_CA.crt
mozilla/ePKI_Root_Certification_Authority.crt
mozilla/emSign_ECC_Root_CA_-_C3.crt
mozilla/emSign_ECC_Root_CA_-_G3.crt
mozilla/emSign_Root_CA_-_C1.crt
mozilla/emSign_Root_CA_-_G1.crt

답변1

아래의 모든 내용은 sedGNU뿐만 아니라 어디에서나 작동합니다 sed.

캐릭터 #코멘트입니다. 이는 "주석 명령"으로 간주할 수 있으며 sed나머지 지시문은 무시할 수 있습니다. 그렇기 때문에 귀하의 명령은하다아무 일도 일어나지 않을 것입니다.

#주소로 사용되는 정규식에 대한 대체 구분 기호 로 사용하려면 를 사용합니다 \#...#. #대체 구분 기호로 사용하려는 문자에는 특별한 것이 아닙니다 .

그 캐릭터들할 수 없다이 경우에 사용되는 구분 기호는 백슬래시와 줄 바꿈입니다. 멀티바이트 문자 사용도 일반적으로 지원되지 않습니다.

특별한 이스케이프 없이 명령() #에서 구분 기호 로 사용할 수 있습니다.ss#...#...#


#단순한 주석 문자 이상의 역할을 하는 유일한 경우는 sed처음 두 문자가 편집 스크립트에 있을 때 입니다 #n. 이는 옵션을 sed사용하여 실행하는 것과 같습니다 -n(각 주기가 끝날 때 편집 버퍼의 기본 출력을 끄는 것).

$ echo hello | sed -e 'y/h/y/'
yello
$ echo hello | sed -e '#n' -e 'y/h/y/'
$ echo hello | sed -e '#n' -e 'y/h/y/' -e p
yello

관련 정보