关于sed awk grep的用法



大家好,我应该用什么命令行来达到这个效果?

这是尝试使用awk和sed,但失败了。请告知。

Original:
server=/example-a.com/127.0.0.1#5353
ipset=/example-a.com/router
server=/example-b.com/127.0.0.1#5353
ipset=/example-b.com/router
server=/example-c.com/127.0.0.1#5353
ipset=/example-c.com/router
Achieve effect:
server=/example-a.com/127.0.0.1#5353
server=/example-a.com/127.0.0.2#5354
ipset=/example-a.com/router
server=/example-b.com/127.0.0.1#5353
server=/example-b.com/127.0.0.2#5354
ipset=/example-b.com/router
server=/example-c.com/127.0.0.1#5353
server=/example-c.com/127.0.0.2#5354
ipset=/example-c.com/router

由于您需要算术,我会使用awk:

awk -F'[#.]' '/^server/ { print $0, ORS $1"."$2"."$3"."$4"."$5+1"#"$6+1 } !/^server/'

输出:

server=/example-a.com/127.0.0.1#5353 
server=/example-a.com/127.0.0.2#5354
ipset=/example-a.com/router
server=/example-b.com/127.0.0.1#5353 
server=/example-b.com/127.0.0.2#5354
ipset=/example-b.com/router
server=/example-c.com/127.0.0.1#5353 
server=/example-c.com/127.0.0.2#5354
ipset=/example-c.com/router

最新更新