8000 csv output in all commands that produce tables · Issue #81 · equinix/metal-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

csv output in all commands that produce tables #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vielmetti opened this issue Aug 31, 2020 · 3 comments
Open

csv output in all commands that produce tables #81

vielmetti opened this issue Aug 31, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@vielmetti
Copy link
Contributor

What problem are you facing?

For reporting purposes, it's useful to take a data extract from the Packet
system and then import it into a spreadsheet for further analysis.

olekukonko/tablewriter#80 describes how to
use the tablewriter package to produce CSV output.

How could the Packet CLI help solve this problem?

Add a --csv or --output csv or similar option to format
tabular output as tables, with a design goal to import into
Excel or Google Sheets.

Alternatively, document how to reformat the JSON or YAML
output into tabular CSV format.

@vielmetti vielmetti added the enhancement New feature or request label Aug 31, 2020
@vielmetti
Copy link
Contributor Author

It is possible to get CSV (or near enough to CSV) output by piping the JSON output into jq, though getting exactly what you want might be difficult with that tool.

An example:

packet device get -p $PACKETPROJECT --include created_at,ip_addresses.address -j | jq -c '.[] |[.hostname,.id,.created_at,.ip_addresses[].address]'

with this output

["freebsd-ewr1","116abfa3-b1c7-xxxx-a559-3a48e691a419","2020-08-30T02:04:30Z","147.75.67.3","2604:1380:0:4300::3","10.99.102.3"]
["debian10-ewr1","8b6695c5-xxxx-4c28-94a2-922fda96aae7","2020-08-30T02:05:37Z","147.75.67.1","2604:1380:0:4300::5","10.99.102.5"]
["qualcomm-01","18cc6bf8-xxxx-4025-9e01-f7cd894ae6d2","2020-05-21T04:52:12Z","147.75.47.222","2604:1380:4111:9d00::1","10.32.50.129"]
["bastion-01","6105741f-14ee-xxxx-8fd9-e580af929ba2","2020-05-20T16:44:22Z","147.75.76.43","2604:1380:0:4300::1","10.99.102.1"]
["mon1","2f07a39f-xxxx-4619-87f9-432be941c892","2020-06-15T11:37:32Z","139.178.68.41","2604:1380:1000:e800::1","10.88.127.1"]

(slightly redacted output)

@vielmetti
Copy link
Contributor Author

Similar results, perhaps better, with

packet device get -p $FREEBIES  -j | in2csv -f json | csvcut -c id,hostname,ip_addresses/0/address

using the in2csv and csvcut tools from the csvkit package.

@displague
Copy link
Member
displague commented Mar 6, 2023

Here's an example of how you can use the JSON format with jq to get custom tables output (thanks @dlotterman):

$ metal device list -o json | \
  jq -r '.[] | .id + "\t" + (.ip_addresses[]| select ((.address_family==4) and .public==true) | .address|tostring) + "\t" + .state + "\t" + .hostname'
3a500289-10d1-49aa-8214-6d0b55818860	203.0.113.54	active	test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants
0