我正在尝试摆脱JSON文件中的大量内容,以便使用BBEdit准备翻译。
一条线看起来像这样:
"ribbonText1" : "The text that needs to be translated",
我想删除所有内容,所以它最终会像这样:
The text that needs to be translated
任何帮助都非常感谢!!!
答案 0 :(得分:0)
第一个regexp选择sub
中的sting,regexp来删除除文本之外的所有内容。
$ cat r.sh
awk '
/"ribbonText1"[ \t]*:/ {
sub(/^[^:]*:/, "")
sub(/^[^"]*"/, "")
sub(/"[^"]*$/, "")
print
}
' "$@"
用法
$ sh r.sh file
The text that needs to be translated
答案 1 :(得分:0)
假设显示的示例是JSON对象的一部分,并且键名称会有所不同,就像这样......
{
"ribbonText1" : "The text that needs to be translated",
"ribbonText2" : "The text that needs to be translated2",
"ribbonText3" : "The text that needs to be translated3",
"ribbonText4" : "The text that needs to be translated4",
"ribbonText5" : "The text that needs to be translated5",
"ribbonText6" : "The text that needs to be translated6"
}
BBEdit中的这个正则表达式可以解决这个问题:
查找:^\s?[^:]+:\s?"([^"]+)",?$
替换:\1
正如Twometer在评论中指出的那样,这很脆弱。我倾向于使用jq。
cat foo.json | jq '.[]'