我有一个运行在它们上面的服务器和服务的列表,并希望将服务器名称作为前缀附加到以下服务
考虑以下输入
"SERVER": "us-east-1e-421"
"SERVICES.SNMP.STATUS": "ok"
"SERVICES.NTP.LATENCY": "1.644"
"SERVICES.POSTFIX.STATUS": "ok"
"SERVER": "us-west-1c-353"
"SERVICES.SNMP.STATUS": "ok"
"SERVICES.NTP.STATUS": "ok"
"SERVICES.NTP.LATENCY": "1.541"
"SERVICES.RSYNC.STATUS": "ok"
"SERVICES.NGINX.STATUS": "ok"
所以我想要的是
us-east-1e-421 SERVICES.SNMP.STATUS ok
us-east-1e-421 SERVICES.NTP.LATENCY 1.644
us-east-1e-421 SERVICES.POSTFIX.STATUS ok
us-west-1c-353 SERVICES.SNMP.STATUS ok
us-west-1c-353 SERVICES.NTP.STATUS ok
us-west-1c-353 SERVICES.NTP.LATENCY 1.541
us-west-1c-353 SERVICES.RSYNC.STATUS ok
us-west-1c-353 SERVICES.NGINX.STATUS ok
我对单行或基本搜索/替换的基本 sed 没问题,我尝试阅读之前发布的一些 sed 指南,例如https://docstore.mik.ua/orelly/unix/sedawk/appa_03.htm 但这是据我所知,需要一些帮助
sed '/([az] -[az] -[a-z0-9] -[0-9] )/ N; s/\n"/\1 /g'