替换LINUX中的模式

时间:2014-08-19 23:52:01

标签: linux bash shell

2.txt

  

“platform”:“iPhone”,“report_attrs”:{“SKU”:“XYZ123”,“单价”:   “32.25”,“数量”:“3”}

     

“platform”:“android”,“report_attrs”:{“SKU”:“XYZ123”,“单价”:   “32.25”,“数量”:“3”}

我想将,*:*{替换为,

O / P:

  

“平台”:“iPhone”,“SKU”:“XYZ123”,“单价”:“32.25”,“数量”:“3”}

     

“platform”:“android”,“SKU”:“XYZ123”,“单价”:“32.25”,“数量”:   “3”}

这是我试过的:

sed s/,*:*{/,/g 2.txt

1 个答案:

答案 0 :(得分:0)

您的sed正则表达式中的

,*表示匹配零个或多个,:*表示匹配零个或多个:符号。

通过sed,

$ sed 's/,[^:]*:[^{]*{/,/' file

"platform": "iPhone","SKU": "XYZ123","Unit Price": "32.25","Qty": "3"}

"platform": "android","SKU": "XYZ123","Unit Price": "32.25","Qty": "3"}

OR

$ sed 's/,[^{]*{/,/' file

"platform": "iPhone","SKU": "XYZ123","Unit Price": "32.25","Qty": "3"}

"platform": "android","SKU": "XYZ123","Unit Price": "32.25","Qty": "3"}