如何使用awk或者sed替换文本? [英] How to replace text using sed or awk?
问题描述
我有以下的JSON文件:
I have the following json file:
{ "last_modified": {
"type": "/type/datetime",
"value": "2008-04-01T03:28:50.625462" },
"type": { "key": "/type/author" },
"name": "National Research Council. Committee on the Scientific and Technologic Base of Puerto Rico"s Economy.",
"key": "/authors/OL2108538A",
"revision": 1 }
name的值有双引号,我只想用一个单引号(而不是其他任何双引号)替换此双引号。我该怎么办呢?
The name value has a double quote and I only want to replace this double quote with a single quote (not any other double quote). How can I do it?
推荐答案
如果你想repleace单个字符出现的所有,你也可以使用命令 TR
,比awk或者sed简单:
If you want to repleace all occurences of a single character, you can also use the command tr
, simpler than sed or awk:
cat myfile.txt | tr \" \'
注意,两个引号转义。如果您有其他字符不是引号,你只写:
Notice that both quotes are escaped. If you have other chars than quotes, you just write:
cat myfile.txt | tr a A
编辑:请注意,这个问题被编辑后,这个答案不再有效:它取代所有的双引号,不仅是名称属性里面有一个
Note that after the question was edited this answer is no longer valid: it replaces all double quotes, not only the one inside the Name property.
这篇关于如何使用awk或者sed替换文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!