mercredi 28 janvier 2015

Removing mulitple lines


I am trying to write up a command line interfaces that will removes a particular section / lines of codes within a list of json files. By the way, the json file are located within the sub-folders of the main directory


I am pretty new to this but this is the code that I can come up with so far - find -name "*.json" | xargs sed -i "map" but some of the json files I had, its format is slightly different


So far I am seeing the following 2 formats within my list:



{
"tags": {},
"map": {
"KPA": {
"State": True,
"namespace": "KPA01"
}
}
}


or



{
"tags": {
"type": [
"char"
],
"dynamic": true
},
"map": {
"KPA01": {
"State": True,
"namespace": "KPA01"
}
}
}


and basically, I am trying to omit out the map section that it has, so that it will only display the tags section but the presence of commas and [] / {} are making it hard for me. So my output results should be like this:



{
"tags": {}
}


or



{
"tags": {
"type": [
"char"
],
"dynamic": true
}
}


Will this be possible to do so in a command line interface? I heard that jq may be able to do it, however, as I tried executing jq '.map' test.json I am getting parse error: ':' not as part of an object at line 2, column 11 in my terminal. Likewise it also seems to be giving off error if I am using the jq play online..


Any ideas?



Aucun commentaire:

Enregistrer un commentaire