2.txt
"platform": "iPhone","report_attrs": {"SKU": "XYZ123","Unit Price": "32.25","Qty": "3"}
"platform": "android","report_attrs": {"SKU": "XYZ123","Unit Price": "32.25","Qty": "3"}
我想将 ,*:*{
替换为 ,
o/p:
"platform": "iPhone","SKU": "XYZ123","Unit Price": "32.25","Qty": "3"}
"platform": "android","SKU": "XYZ123","Unit Price": "32.25","Qty": "3"}
这是我尝试过的:
sed s/,*:*{/,/g 2.txt
最佳答案
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"}
或者
$ sed 's/,[^{]*{/,/' file
"platform": "iPhone","SKU": "XYZ123","Unit Price": "32.25","Qty": "3"}
"platform": "android","SKU": "XYZ123","Unit Price": "32.25","Qty": "3"}
关于linux - LINUX 中的替换模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25394761/