Monday, 26 August 2013

Format data as a table in bash

Format data as a table in bash

I have an array of JSON data being printed to the terminal (OS X) and I
want the properties of that to be displayed in a table in the terminal.
Sample query:
aws ec2 describe-instances
| jq '[ .[] | .[] | .Instances[] as $ins \
| { groups: $ins.SecurityGroups[].GroupName, \
addresses: [ $ins.PrivateIpAddress, $ins.PublicIpAddress ], \
dns: $ins.PrivateDnsName, \
name: ($ins.Tags[] as $ts | $ts.Key == "Name" | $ts.Value ) } \
| select(.name | contains("prod")) ]'
Stated another way: I want to take the resulting data structure (array of
object that contains properties 'addresses', 'groups', 'dns', 'name') and
shove each object into a line of a table, inside the terminal/bash.
I don't mind to let the data be EOF-ed before the table starts drawing.

No comments:

Post a Comment