使用Sed替换模式删除字符串

时间:2019-02-21 22:21:03

标签: unix sed

我想使用 unix sed reqular表达式

替换不需要的字符串

输入字符串

services:
    mail_sent_subscriber:
        class: Fidelise\SignUpBundle\EventListener\SentMailsListener
        tags:
            - { name: kernel.event_subscriber }

必需的字符串

echo ',"wanted1":"value1","unwanted";"unwanted";"wanted2":"value2",'

1 个答案:

答案 0 :(得分:0)

尝试这个

脚本

echo ',"wanted1":"value1","unwanted";"unwanted";"wanted2":"value2",' | sed 's/,//g; s/"unwanted"//g; s/;//g; s/""/","/g'

输出

"wanted1":"value1","wanted2":"value2"