como usar tr para excluir uma sequência de caracteres octais?

como usar tr para excluir uma sequência de caracteres octais?

Estou tentando deletar isto: --More--de um arquivo .dat, este é um fragmento do arquivo para dar um exemplo:

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

Usando um editor de texto hexadecimal, identifiquei os caracteres não visíveis insira a descrição da imagem aqui

Agora estou tentando deletar toda a sequência de caracteres mas não consegui,

essas são minhas tentativas:

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

Qualquer ajuda?

Obrigado.

é assim que parece no 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

Responder1

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

  • Em vez de escrever, s/ */../minha preferência pessoal é s/[ ]*/../porque fica *visivelmente anexado ao átomo à esquerda quando é um espaço/TAB.
  • GNU sedtem o recurso de correspondência hexadecimal com o\xhexadecimalseqüência.

Responder2

A solução mais simples é pensar ao contrário. Em vez de tentar definir os caracteres que você não deseja, defina aqueles que você deseja e remova qualquer outro:

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

Isso excluirá a string --More--e 0 ou mais caracteres depois dela que não sejam um espaço, uma letra ou um número. Dependendo dos seus dados, talvez seja necessário ajustar um pouco esse conjunto (por exemplo, também permitir _ou o que você precisar).

Agora, o primeiro --More--da sua pergunta parece conter caracteres de retrocesso (octal 010, Hex 7, ASCII \b), então você também pode fazer:

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

Ou, para remover --More--também:

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

informação relacionada