如果行在gawk中包含另一个字符串,则替换字符串

时间:2019-09-17 15:00:19

标签: bash awk terminal

在文本文件中,我想找到包含 4294967295

的任何行
<DVAMarker>{"DVAMarker":{"mCuePointList":[{"mKey":"marker_guid","mValue":"4e469eea-d7a9-49e8-b034-a4001272ddfb"},{"mKey":"keywordExtDVAv1_87b5cf3c-5b50-4ceb-8ae4-0978c58d3775","mValue":"{\"color\":4294967295}"}],"mDuration":{"ticks":3911846400000},"mMarkerID":"9c6d9e19-3790-4e25-bd3f-8808f1ce73ea","mName":"Montenegro","mStartTime":{"ticks":88062266880000},"mType":"Comment"}}</DVAMarker>

然后在“ mCuePointList” 之前插入 mComment“:” BLUE“ ,因此结果看起来像

<DVAMarker>{"DVAMarker":{mComment":"BLUE", "mCuePointList":[{"mKey":"marker_guid","mValue":"4e469eea-d7a9-49e8-b034-a4001272ddfb"},{"mKey":"keywordExtDVAv1_87b5cf3c-5b50-4ceb-8ae4-0978c58d3775","mValue":"{\"color\":4294967295}"}],"mDuration":{"ticks":3911846400000},"mMarkerID":"9c6d9e19-3790-4e25-bd3f-8808f1ce73ea","mName":"Montenegro","mStartTime":{"ticks":88062266880000},"mType":"Comment"}}</DVAMarker>

我在Mac上的Terminal中使用bash和gawk。

1 个答案:

答案 0 :(得分:3)

我不确定这是json还是xml(虽然我不是专家,但对我来说并不看),如果可以尝试使用awk,就可以使用。

awk '/4294967295/{sub(/"mCuePointList"/,"mComment\":\"BLUE\",&")} 1' Input_file