¿Cómo usar tr para eliminar una secuencia de caracteres octales?

¿Cómo usar tr para eliminar una secuencia de caracteres octales?

Estoy intentando eliminar esto: --More--de un archivo .dat, este es un fragmento del archivo para dar un ejemplo:

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 un editor de texto hexadecimal, identifiqué los caracteres no visibles. ingrese la descripción de la imagen aquí

Ahora estoy intentando borrar toda la secuencia de caracteres pero no lo he logrado,

esos son mis intentos:

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

¿Alguna ayuda?

Gracias.

así es como se ve en 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

Respuesta1

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

  • En lugar de escribir, s/ */../mi preferencia personal es s/[ ]*/../cómo hace que *el átomo esté visiblemente adherido a su izquierda cuando es un espacio/TAB.
  • GNU sedtiene la función de emparejar hexadecimalmente con el\xdígito hexadecimalsecuencia.

Respuesta2

La solución más sencilla es pensar al revés. En lugar de intentar definir los caracteres que no desea, defina los que sí desea y elimine todo lo demás:

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

Eso eliminará la cadena --More--y 0 o más caracteres posteriores que no sean un espacio, una letra o un número. Dependiendo de sus datos, es posible que tenga que modificar un poco esa configuración (por ejemplo, también permitir _o lo que necesite).

Ahora, el primero --More--de su pregunta parece contener caracteres de retroceso (octal 010, Hex 7, ASCII \b), por lo que también podría hacer:

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

O, para eliminar --More--también:

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

información relacionada