【问题标题】:How to replace characters in sed with other characters如何用其他字符替换sed中的字符
【发布时间】:2018-02-22 16:48:02
【问题描述】:

这是我得到的输出。

"last_name:""abcd","email:""abc.com","first_name:""xyz"

期望的输出是:

"last_name":"abcd","email":"abc.com","first_name":"xyz"

【问题讨论】:

标签: sed character


【解决方案1】:

使用substitute 命令:

echo '"last_name:""abcd","email:""abc.com","first_name:""xyz"' | 
sed 's/:""/":"/g'

输出:

"last_name":"abcd","email":"abc.com","first_name":"xyz"

【讨论】:

    【解决方案2】:

    这个简单的sed 可能对您有所帮助:

    sed 's/:""/":"/g'   Input_file
    

    解释: sed 使用目标(或新字符串/值)":"(in这个案例)。 g 选项确保替换在行中全局发生。

    解决方案 2: 现在也添加 awk 解决方案:

    awk '{gsub(/:\042\042/,"\042:\042")} 1'  Input_file
    

    注意:如果您想将输出保存在 Input_file 本身中,请在上面的代码中使用sed -i,尽管sed

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-09
      • 1970-01-01
      相关资源
      最近更新 更多