0

We are getting JSON data using curl and data is getting appended to the same file by calling endpoint URL using curl in a loop.

Due to this, header of JSON output is being repetitive in same file. so I want to remove multiple headers from file except the first one using shell.

str1="]}}{"QueryResult": {"APIMajor": "2", "APIMinor": "0", "Errors": [], "Warnings": [], "TotalResultCount": 272, "StartInd": 201, "PageSize": 200, "Results": ["

str2=", "

How do I replace str1 in a JSON file with str2 using shell?

Radek Simko
  • 15,886
  • 17
  • 69
  • 107
user2416693
  • 73
  • 1
  • 1
  • 3
  • 1
    Are you just trying to find & replace a string with string in another string? If so, I'd just give a go to `awk` and/or `sed`. Though it might be worth looking at some tools to deal with JSON: http://stackoverflow.com/questions/1955505/parsing-json-with-sed-and-awk – Radek Simko May 27 '14 at 09:26
  • I tried sed but no luck..it is not replacing values, Here is code I am using str1="]}}{"\"QueryResult"\": {"\"_APIMajor"\": "\"2"\", "\"_APIMinor"\": "\"0"\", "\"Errors"\": [], "\"Warnings"\": [], "\"TotalResultCount"\": 272, "\"StartInd"\": 201, "\"PageSize"\": 200, "\"Results"\": [" str2=", " sed 's/${str1}/${str2}/g' -i filename – user2416693 May 27 '14 at 10:07

0 Answers0