0
BEGIN {
    q = "\""
    FS = OFS = q ", " q
}
{ 
    split($1, arr, ": " q)
    for(i in arr ) {
        if(arr[i] == "name") {
            gsub(q, "'", arr[i+1])
            # print arr[1] ": " q arr[2], $2, $3  
        }
    }
}

我有一个 json 文件,一些数据是这样的:

{"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}

名称的值有双引号,我只想将双引号替换为单引号,而不是全部双引号,请告诉我如何修复它?

4

1 回答 1

1
awk '{for(i=1;i<=NF;i++) if($i~/name/){ gsub("\042","\047",$(i+1)) }}1' file
于 2010-08-06T13:57:06.463 回答