2010-08-06 8 views
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} 

이름의 값을 큰 따옴표, 나는 단지 하나의 큰 따옴표를 대체 할이 따옴표, 모든 이중 인용 부호가 아니라 어떻게 해결할 지 말해 주시겠습니까?

+0

Python 또는 Perl (또는 독립 실행 형)에서 적절한 JSON 구문 분석기를 사용하는 것이 좋습니다. –

+0

가능한 중복 [도움이 필요합니다! sed 또는 awk 텍스트 바꾸기 방법] (http://stackoverflow.com/questions/3422103/need-help-sed-or-awk-how-to-replace-text) –

답변

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