Skip to main content
added 1 character in body; edited tags
Source Link
MD. Khairul Basar
  • 5.1k
  • 15
  • 43
  • 65

I am trying to filter through tags of this JSON output (http://pastebin.com/RjjBH7g4JSON output)

Selecting through the Tags[] and display the selected values if the key exist.

My jq filter looks like this :

jq -r ".Reservations[]
 | [.OwnerId,
    .Instances[].InstanceId,
    .Instances[].Placement.AvailabilityZone,
    (.Instances[].Tags[]?|select(.Key==OtherTag)|.Value),
    (.Instances[].Tags[]?|select(.Key==Name)|.Value) ]
 | @csv"

The output looks like this

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,webserver2"

I would like it to include the unfounded select tags and fill it in as empty field in the csv like below :

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,,webserver2"

What should I do in jq to achieve that? Can someone give me an example?

I am trying to filter through tags of this JSON output (http://pastebin.com/RjjBH7g4)

Selecting through the Tags[] and display the selected values if the key exist.

My jq filter looks like this :

jq -r ".Reservations[]
 | [.OwnerId,
    .Instances[].InstanceId,
    .Instances[].Placement.AvailabilityZone,
    (.Instances[].Tags[]?|select(.Key==OtherTag)|.Value),
    (.Instances[].Tags[]?|select(.Key==Name)|.Value) ]
 | @csv"

The output looks like this

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,webserver2"

I would like it to include the unfounded select tags and fill it in as empty field in the csv like below :

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,,webserver2"

What should I do in jq to achieve that? Can someone give me an example?

I am trying to filter through tags of this JSON output

Selecting through the Tags[] and display the selected values if the key exist.

My jq filter looks like this :

jq -r ".Reservations[]
 | [.OwnerId,
    .Instances[].InstanceId,
    .Instances[].Placement.AvailabilityZone,
    (.Instances[].Tags[]?|select(.Key==OtherTag)|.Value),
    (.Instances[].Tags[]?|select(.Key==Name)|.Value) ]
 | @csv"

The output looks like this

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,webserver2"

I would like it to include the unfounded select tags and fill it in as empty field in the csv like below :

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,,webserver2"

What should I do in jq to achieve that? Can someone give me an example?

format for easy reading; + tag
Source Link
peak
  • 119.4k
  • 22
  • 186
  • 218

I am trying to filter through tags of this JSON output (http://pastebin.com/RjjBH7g4)

Selecting through the Tags[] and display the selected values if the key exist.

My jq filter looks like this :

jq -r ".Reservations[] 
 | [.OwnerId,
    .Instances[].InstanceId,
    .Instances[].Placement.AvailabilityZone,
    (.Instances[].Tags[]?|select(.Key==OtherTag)|.Value),
    (.Instances[].Tags[]?|select(.Key==Name)|.Value) ] 
 |@csv"| @csv"

The output looks like this

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,webserver2"

I would like it to include the unfounded select tags and fill it in as empty field in the csv like below :

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,,webserver2"

What doshould I usedo in jq filter to achieve that? candCan someone give me an example?

Thanks

I am trying to filter through tags of this JSON output (http://pastebin.com/RjjBH7g4)

Selecting through the Tags[] and display the selected values if the key exist.

My jq filter looks like this :

jq -r ".Reservations[] | [.OwnerId, .Instances[].InstanceId, .Instances[].Placement.AvailabilityZone,(.Instances[].Tags[]?|select(.Key==OtherTag)|.Value),(.Instances[].Tags[]?|select(.Key==Name)|.Value) ] |@csv"

The output looks like this

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,webserver2"

I would like it to include the unfounded select tags and fill it in as empty field in the csv like below :

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,,webserver2"

What do I use in jq filter to achieve that? cand someone give me an example?

Thanks

I am trying to filter through tags of this JSON output (http://pastebin.com/RjjBH7g4)

Selecting through the Tags[] and display the selected values if the key exist.

My jq filter looks like this :

jq -r ".Reservations[] 
 | [.OwnerId,
    .Instances[].InstanceId,
    .Instances[].Placement.AvailabilityZone,
    (.Instances[].Tags[]?|select(.Key==OtherTag)|.Value),
    (.Instances[].Tags[]?|select(.Key==Name)|.Value) ] 
 | @csv"

The output looks like this

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,webserver2"

I would like it to include the unfounded select tags and fill it in as empty field in the csv like below :

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,,webserver2"

What should I do in jq to achieve that? Can someone give me an example?

Source Link
hutanrimba
  • 149
  • 1
  • 10

jq filter to include unfound select

I am trying to filter through tags of this JSON output (http://pastebin.com/RjjBH7g4)

Selecting through the Tags[] and display the selected values if the key exist.

My jq filter looks like this :

jq -r ".Reservations[] | [.OwnerId, .Instances[].InstanceId, .Instances[].Placement.AvailabilityZone,(.Instances[].Tags[]?|select(.Key==OtherTag)|.Value),(.Instances[].Tags[]?|select(.Key==Name)|.Value) ] |@csv"

The output looks like this

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,webserver2"

I would like it to include the unfounded select tags and fill it in as empty field in the csv like below :

"xxxxxxxxxx9,i-d414ce0b,ap-southeast-2b,,webserver2"

What do I use in jq filter to achieve that? cand someone give me an example?

Thanks