sed实现grep -Po 功能

sed实现grep -Po 功能

sed -n选项,s命令,和p命令 三个同时使用,如下:
[root@ansible-server-bm scripts]# cat /datas/shells/cdn_config/cdn_domainName.property
##Don't delete the file
domainName=img.xxx.com
[root@ansible-server-bm scripts]# sed -n 's/^domainName=\(.*\)/\1/p' /data/shell/cdn_config/cdn_domainName.property 
img.xxx.com

生产案列1:
[root@ansible-server-xray2tl cdn_config]# cat xx 
job-2-xray2tl.production:
    ----------
    pid:
        27152
    retcode:
        0
    stderr:
    stdout:
        img.b-maintain.com
web-3-xray2tl.production:
    ----------
    pid:
        374073
    retcode:
        0
    stderr:
    stdout:
        img.xxxtyt.com
job-1-xray2tl.production:
    ----------
    pid:
        59904
    retcode:
        0
    stderr:
    stdout:
        img.b-maintain.com
admin-1-xray2tl.production:
    ----------
    pid:
        338925
    retcode:
        0
    stderr:
    stdout:
        img.b-maintain.com
web-4-xray2tl.production:
    ----------
    pid:
        376313
    retcode:
        0
    stderr:
    stdout:
        img.xxxtyt.com
web-1-xray2tl.production:
    ----------
    pid:
        52811
    retcode:
        0
    stderr:
    stdout:
        img.xxxtyt.com
web-2-xray2tl.production:
    ----------
    pid:
        365946
    retcode:
        0
    stderr:
    stdout:
        img.xxxtyt.com

[root@ansible-server-xray2tl cdn_config]# sed -n '/xray2tl/{h;:z;n;/stdout/!bz;{n;H;g;s/\n//;p}}' xx
job-2-xray2tl.production:        img.b-maintain.com
web-3-xray2tl.production:        img.xxxtyt.com
job-1-xray2tl.production:        img.b-maintain.com
admin-1-xray2tl.production:        img.b-maintain.com
web-4-xray2tl.production:        img.xxxtyt.com
web-1-xray2tl.production:        img.xxxtyt.com
web-2-xray2tl.production:        img.xxxtyt.com