如何用其他字符替换SED中的字符



这是我要获得的输出。

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

所需的输出为:

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

使用 s ubstitute 命令:

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

输出:

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

这个简单的 sed可能会在同一方面帮助您:

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

说明: sed用目标(或新的字符串/值(":"(在这种情况下(替换源:""(在这种情况下(的方法。g选项确保在线上全球发生替代。

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

awk '{gsub(/:4242/,"42:42")} 1'  Input_file

注意:如果要在input_file本身中保存输出,然后在上述代码中使用sed -i,尽管sed

最新更新