views:

37

answers:

1
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  
}

} }

a json file have 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}

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?

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