bash sed/awk/perl:删除一组字符,除非匹配特定字符串

bash sed/awk/perl: removing a group of characters except when it matches specific strings

例如,下面的列表...:

- name_1: name_11:value-1
  name_2: value-2
  name_3: http://value-3
- name_4: https://value-4
  name_5: name_51:value-5
  name_6: value-61:value-62:value-63

...必须转化为:

- name_1: value-1
  name_2: value-2
  name_3: http://value-3
- name_4: https://value-4
  name_5: value-5
  name_6: value-61:value-62:value-63

以下 sed 命令删除所有第二个 "name" 字段,包括匹配 'http[s]*':

的字段
sed -E 's|([[:blank:]-]+[[:alnum:]_\.-]+:[[:blank:]]+)[[:alnum:]_\.-]+:([^:]+)$||g' file
- name_1: value-1
  name_2: value-2
  name_3: //value-3
- name_4: //value-4
  name_5: value-5
  name_6: value-61:value-62:value-63

有什么建议吗?

使用交替 ((https?:)|[[:alnum:]_.-]+:) 捕获 http:https: :

sed -E 's/([[:blank:]-]+[[:alnum:]_.-]+:[[:blank:]]+)((https?:)|[[:alnum:]_.-]+:)([^:]+)$//g' file