tr을 사용하여 8진수 문자 시퀀스를 삭제하는 방법은 무엇입니까?

tr을 사용하여 8진수 문자 시퀀스를 삭제하는 방법은 무엇입니까?

이것을 삭제하려고 합니다. --More--.dat 파일에서 다음은 예를 들어 파일의 일부입니다.

Device ID: N7K-LAN(JAF1651ANDL)
  IP address: 148.228.4.192
Interface: GigabitEthernet0/1,  Port ID (outgoing port): Ethernet7/19
Device ID: CIRC_INF_IDF1
  IP address: 148.228.107.252
Interface: FastEthernet0/20,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.107.252
Device ID: CIRC_INF_IDF3
  IP address: 148.228.107.250
 --More--         Interface: FastEthernet0/23,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.107.250
Device ID: CIRC_INF_IDF2
  IP address: 148.228.107.251
Interface: FastEthernet0/22,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.107.251
Device ID: SEP1CAA0711CFBE
 --More--           IP address: 148.228.199.103
Interface: FastEthernet0/2,  Port ID (outgoing port): Port 1
Device ID: SEP1CAA0711CD67
  IP address: 148.228.199.154
Interface: FastEthernet0/5,  Port ID (outgoing port): Port 1

Hex 텍스트 편집기를 사용하여 보이지 않는 문자를 식별했습니다. 여기에 이미지 설명을 입력하세요

이제 전체 문자 시퀀스를 삭제하려고 하는데 성공하지 못했습니다.

그게 내 시도입니다.

tr -d --More--           < tabladetallada.dat >temporaltabla.dat

tr -d '\015' '\012' '\20' '\055' '\055' '\115' < tabladetallada.dat >temporaltabla.dat

sed 's/--More--␣//' tabladetallada.dat>tabladetallada2.dat

tr -d ' --More-- ^H^H^H^H^H^H^H^H^H        ^H^H^H^H^H^H^H^H^H' < tabladetallada.dat >temporaltabla.dat

도움이 필요하세요?

감사해요.

vi에서는 다음과 같이 보입니다.

Device ID: N7K-LAN(JAF1651ANDL)^M
  IP address: 148.228.4.192^M
Interface: GigabitEthernet0/1,  Port ID (outgoing port): Ethernet7/19^M
Device ID: CIRC_INF_IDF1^M
  IP address: 148.228.107.252^M
Interface: FastEthernet0/20,  Port ID (outgoing port): GigabitEthernet0/1^M
  IP address: 148.228.107.252^M
Device ID: CIRC_INF_IDF3^M
  IP address: 148.228.107.250^M
 --More-- ^H^H^H^H^H^H^H^H^H        ^H^H^H^H^H^H^H^H^HInterface: FastEthernet0/23,  Port ID (outgoing port): GigabitEthernet0/1^M
  IP address: 148.228.107.250^M
Device ID: CIRC_INF_IDF2^M
  IP address: 148.228.107.251^M
Interface: FastEthernet0/22,  Port ID (outgoing port): GigabitEthernet0/1^M
  IP address: 148.228.107.251^M
Device ID: SEP1CAA0711CFBE^M
 --More-- ^H^H^H^H^H^H^H^H^H        ^H^H^H^H^H^H^H^H^H  IP address: 148.228.199.103^M
Interface: FastEthernet0/2,  Port ID (outgoing port): Port 1^M
Device ID: SEP1CAA0711CD67^M
  IP address: 148.228.199.154^M
Interface: FastEthernet0/5,  Port ID (outgoing port): Port 1^M
Device ID: SEP1CAA0711D11A^M
  IP address: 148.228.199.4^M
Interface: FastEthernet0/10,  Port ID (outgoing port): Port 1^M
Device ID: SEPece1a985bb74^M
  IP address: 148.228.199.21^M
Interface: FastEthernet0/12,  Port ID (outgoing port): Port 1^M
Device ID: SEPf84f5794c5c4^M
  IP address: 148.228.199.23^M
Interface: FastEthernet0/11,  Port ID (outgoing port): Port 1^M
Device ID: SEP1CAA0711D276^M
  IP address: 148.228.199.102^M
 --More-- ^H^H^H^H^H^H^H^H^H        ^H^H^H^H^H^H^H^H^HInterface: FastEthernet0/9,  Port ID (outgoing port): Port 1^M
Device ID: SEPece1a985b5d5^M
  IP address: 148.228.199.24^M
Interface: FastEthernet0/14,  Port ID (outgoing port): Port 1^M
Device ID: SEP1CAA0711497C^M
Interface: FastEthernet0/4,  Port ID (outgoing port): Port 1^M
Device ID: SEPf84f5794c8c2^M
  IP address: 148.228.199.22^M
Interface: FastEthernet0/3,  Port ID (outgoing port): Port 1^M
Device ID: Circulo_Camaras4^M
 --More-- ^H^H^H^H^H^H^H^H^H        ^H^H^H^H^H^H^H^H^H  IP address: 148.228.101.5^M
Interface: FastEthernet0/24,  Port ID (outgoing port): GigabitEthernet1/0/24^M
  IP address: 148.228.101.5^M

답변1

sed -e 's/^[ ]*--More--.*\x8//' -e 's/\xD$//'

  • s/ */../내 개인적인 취향을 쓰는 대신 공백/TAB일 때 왼쪽에 있는 원자에 눈에 띄게 부착되는 s/[ ]*/../것이 좋습니다.*
  • GNU sed16진수 일치 기능이 있습니다.\x16진수순서.

답변2

가장 간단한 해결책은 반대로 생각하는 것입니다. 원하지 않는 문자를 정의하는 대신, 원하는 문자를 정의하고 다른 것은 모두 제거하세요.

sed 's/--More--[^ a-zA-Z0-9]*//' file 

--More--그러면 공백, 문자 또는 숫자가 아닌 문자열과 그 뒤의 0개 이상의 문자가 삭제됩니다 . 데이터에 따라 해당 설정을 약간 조정해야 할 수도 있습니다(예: 허용하거나 _필요한 모든 항목).

--More--이제 질문의 첫 번째 항목 에는 백스페이스 문자(8진수 010, 16진수 7, ASCII \b)가 포함되어 있는 것 같으므로 다음과 같이 할 수도 있습니다.

perl -pe 's/[\b]//g' file

또는 다음 --More--도 제거하려면 다음을 수행하십시오.

perl -pe 's/--More--[\b]+//g' file

관련 정보