我目前有一个yaml文件(这个文件很大,格式如下):
- created_at: 2021-01-18 15:11:44
created_by: joe
hostname: sfo
ip: 1.1.1.1
opersys: tmsh
platform: f5
role: lb
type: loadbalancer
- created_at: 2021-01-18 15:11:44
created_by: joe
hostname: sjc
ip: 2.2.2.2
opersys: tmsh
platform: f5
role: lb
type: loadbalancer我想在每第8行插入一个新文本(serial_num: xxxxx),这样看起来就像这样:
- created_at: 2021-01-18 15:11:44
created_by: joe
hostname: sfo
ip: 1.1.1.1
opersys: tmsh
platform: f5
role: lb
type: loadbalancer
serial_num: xxxxx
- created_at: 2021-01-18 15:11:44
created_by: joe
hostname: sjc
ip: 2.2.2.2
opersys: tmsh
platform: f5
role: lb
type: loadbalancer
serial_num: xxxxx发布于 2021-01-19 03:33:40
纯Vim,使用:help :global和:help :put
" after every line matching 'type:'
:g/type:/put=' serial_num: xxxxx'
" before every line matching 'type:'
:g/type:/put!=' serial_num: xxxxx'纯Vim,使用:help :global和:help :normal
" after every line matching 'type:'
:g/type:/normal oserial_num: xxxxx
" before every line matching 'type:'
:g/type:/normal Oserial_num: xxxxx发布于 2021-01-19 03:37:59
使用GNU Sed
sed '/type: /a\ serial_num: xxxxx' your_filehttps://stackoverflow.com/questions/65777600
复制相似问题