gpt4 book ai didi

linux - LINUX 中的替换模式

转载 作者:太空宇宙 更新时间:2023-11-04 03:54:01 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com