특정 문자 뒤의 공백 제거

특정 문자 뒤의 공백 제거

sed명령을 사용하여 단어를 제거하고 있습니다 --More--.

sed 's/--More--\s*/ /' tabladetallada.dat

원본 파일은 다음과 같습니다.

Device ID: BIOTERIO
  IP address: 148.228.83.189
Interface: GigabitEthernet1/0/6,  Port ID (outgoing port): GigabitEthernet0/1
 --More--         Device ID: N7K-LAN(JAF1651ANDL)
  IP address: 148.228.4.192
Interface: GigabitEthernet1/0/1,  Port ID (outgoing port): Ethernet7/23
Device ID: LAB_PESADO
  IP address: 148.228.131.130
Interface: GigabitEthernet1/0/11,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.131.130
Device ID: Arquitectura_Salones
  IP address: 148.228.135.61
Interface: GigabitEthernet1/0/9,  Port ID (outgoing port): GigabitEthernet0/49
  IP address: 148.228.135.61
Device ID: CIVIL_253
  IP address: 148.228.132.253
 --More--         Interface: GigabitEthernet1/0/4,  Port ID (outgoing port): GigabitEthernet1/0/52
  IP address: 148.228.132.253
Device ID: Arquitectura
  IP address: 148.228.134.253
Interface: GigabitEthernet1/0/3,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.134.253
Device ID: ING_CIVIL
  IP address: 148.228.133.251
Interface: GigabitEthernet1/0/7,  Port ID (outgoing port): GigabitEthernet0/2
  IP address: 148.228.133.251
Device ID: ING_CIVIL_DIR
  IP address: 148.228.4.188
Interface: GigabitEthernet1/0/10,  Port ID (outgoing port): GigabitEthernet0/2
Device ID: Ingenieria_Posgrado
  IP address: 148.228.137.253
Interface: GigabitEthernet1/0/8,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.137.253
Device ID: Biblio_Barragan
  IP address: 148.228.136.61
Interface: GigabitEthernet1/0/2,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.136.61
Device ID: Electronica_Edif_3
 --More--           IP address: 148.228.130.253
Interface: GigabitEthernet1/0/5,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.130.253

단어를 삭제한 후에도 다음과 같은 공백이 남아 있는데 어떻게 삭제하나요?

Device ID: BIOTERIO
  IP address: 148.228.83.189
Interface: GigabitEthernet1/0/6,  Port ID (outgoing port): GigabitEthernet0/1
           Device ID: N7K-LAN(JAF1651ANDL)
  IP address: 148.228.4.192
Interface: GigabitEthernet1/0/1,  Port ID (outgoing port): Ethernet7/23
Device ID: LAB_PESADO
  IP address: 148.228.131.130
Interface: GigabitEthernet1/0/11,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.131.130
Device ID: Arquitectura_Salones
  IP address: 148.228.135.61
Interface: GigabitEthernet1/0/9,  Port ID (outgoing port): GigabitEthernet0/49
  IP address: 148.228.135.61
Device ID: CIVIL_253
  IP address: 148.228.132.253
           Interface: GigabitEthernet1/0/4,  Port ID (outgoing port): GigabitEthernet1/0/52
  IP address: 148.228.132.253
Device ID: Arquitectura
  IP address: 148.228.134.253
Interface: GigabitEthernet1/0/3,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.134.253
Device ID: ING_CIVIL
  IP address: 148.228.133.251
Interface: GigabitEthernet1/0/7,  Port ID (outgoing port): GigabitEthernet0/2
  IP address: 148.228.133.251
Device ID: ING_CIVIL_DIR
  IP address: 148.228.4.188
Interface: GigabitEthernet1/0/10,  Port ID (outgoing port): GigabitEthernet0/2
Device ID: Ingenieria_Posgrado
  IP address: 148.228.137.253
Interface: GigabitEthernet1/0/8,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.137.253
Device ID: Biblio_Barragan
  IP address: 148.228.136.61
Interface: GigabitEthernet1/0/2,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.136.61
Device ID: Electronica_Edif_3
             IP address: 148.228.130.253
Interface: GigabitEthernet1/0/5,  Port ID (outgoing port): GigabitEthernet0/1
  IP address: 148.228.130.253

답변1

교체는 다음과 같아야합니다

s/--More-- */ /

또는

s/--More--[[:blank:]]*/ /

sed"공간" 에 대해 모르지만 \s문자 그대로라고 생각하십시오 s.

␣*(공백 + *)는 0개 이상의 공백과 일치합니다.

[[:blank:]]*0개 이상의 공백이나 탭과 일치합니다.

답변2

sed다음과 같이 사용할 수 있습니다 .

sed 's/--More--[[:space:]]//g' file

관련 정보