Read YAML and Display as Table in Linux
Debugging YAML configs often means squinting at raw nested data. yq combined with column can display it as a clean table instead.
Install yq if not already installed.
Example YAML file (data.yaml):
items:
- name: Alice
email: alice@example.com
- name: Bob
email: bob@example.com
Quick one-liner:
yq -r '.items[] | [.name, .email] | @tsv' data.yaml | column -s $'\t' -t
Same command, step by step:
yq -r '
.items[] # loop through each item in the list
| [.name, .email] # select the name and email fields
| @tsv # format as tab-separated values
' data.yaml | column -t # pipe to column for neat table view
Output:
Alice alice@example.com
Bob bob@example.com
Works well for any YAML with a consistent list structure. Just adjust the field names in the yq expression to match the data.