0

I have a JSON file from which I need to extract a few parameters and write into another file:

devDependencies": {
"gulp": "^3.9.1",
"gulp-angular-templatecache": "^1.9.1",
"gulp-bump": "^1.0.0"
}

I want to write a file that contains only

gulp gulp-angular-templatecache gulp-bump

How can I do that using a shell script?

Maximillian Laumeister
  • 19,884
  • 8
  • 59
  • 78
Joy
  • 505
  • 2
  • 5
  • 13
  • 2
    Possible duplicate of [Parsing JSON with UNIX tools](http://stackoverflow.com/questions/1955505/parsing-json-with-unix-tools) – Benjamin W. Dec 12 '16 at 03:06
  • Show us what you have tried yet... ;-) – kebs Dec 14 '16 at 08:53
  • As I am new in jq, I have use it in conjunction with shell. I am pretty sure this can be handle by jq alone. I just strip out portion of data from the jason file using jq and then use shell to remove quotes from the string using shell.: jq ".devDependencies | to_entries[] | .key" package.json > devdep – Joy Dec 15 '16 at 10:54

1 Answers1

1
echo $(grep ^\" file| cut -d\" -f2)

But you shouldn't do any more complex json parsing with bash. This is also a hackish solution.

Ipor Sircer
  • 3,069
  • 3
  • 10
  • 15
  • Any better idea how I can do this? – Joy Dec 12 '16 at 02:33
  • 1
    Thanks. I have used below command and able to extract the portion like below: cat package.json | `pwd`/jq '.devDependencies' { "angular-cookies": "1.5.8", "chai": "^3.4.1", "del": "^1.2.0", "gulp": "^3.9.1", "gulp-angular-templatecache": "^1.9.1", "gulp-bump": "^1.0.0" } Now I really wanted to extract the keys of every field (e.g. angular-cookies chai del ...) Not able to figure how I can do that? appreciate your help – Joy Dec 12 '16 at 16:08