开发者

Replace double quotes to single quotes with awk

开发者 https://www.devze.com 2023-01-10 06:43 出处:网络
BEGIN { q = \"\\\"\" FS = OFS = q \", \" q } { split($1, arr, \": \" q) for(i in arr ) { if(arr[i] == \"name\") {
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  
        }
开发者_Python百科    }
}

I have a json file, some data like this:

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

The name's value have a double quote, I only want to replace the double quote to single quote , not the all double quote, please tell me how to fix it?


awk '{for(i=1;i<=NF;i++) if($i~/name/){ gsub("\042","\047",$(i+1)) }}1' file
0

精彩评论

暂无评论...
验证码 换一张
取 消