Formatting csv files in shell

Often it is easier to read csv files if they are formatted as a table. One of my ansible playbooks outputs a list of machines o a csv file.

The playbook in action

tingo@kg-core2:/zs/tingo/personal/projects/2020/ansible_fbsd/infrastructure_home $ ansible-playbook os-report.yml

PLAY [all] *****************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************
ok: [kg-omni1]
ok: [v7]
ok: [vm2]
ok: [bpi]
ok: [vm4]
ok: [f6]
ok: [vm3]
fatal: [steamos]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "failed": true, "msg": "ansible-core requires a minimum of Python2 version 2.6 or Python3 version 3.5. Current version: 3.4.2 (default, Mar 20 2019, 13:01:09) [GCC 4.9.2]"}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}
ok: [wiki2]
ok: [web]
ok: [proxy]
ok: [ndwiki]
ok: [rtl433]
ok: [c1]
ok: [c2]
ok: [web2]
fatal: [xh61v]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 10.1.161.39 port 22: Operation timed out", "unreachable": true}
ok: [hdmipi]

TASK [get current user] ****************************************************************************************************************************
changed: [proxy -> localhost]

TASK [clean file] **********************************************************************************************************************************
changed: [proxy -> localhost]

TASK [fill os information] *************************************************************************************************************************
changed: [vm2 -> localhost]
changed: [web -> localhost]
changed: [proxy -> localhost]
changed: [kg-omni1 -> localhost]
changed: [v7 -> localhost]
changed: [vm3 -> localhost]
changed: [wiki2 -> localhost]
changed: [bpi -> localhost]
changed: [vm4 -> localhost]
changed: [f6 -> localhost]
changed: [hdmipi -> localhost]
changed: [rtl433 -> localhost]
changed: [ndwiki -> localhost]
changed: [web2 -> localhost]
changed: [c1 -> localhost]
changed: [c2 -> localhost]

PLAY RECAP *****************************************************************************************************************************************
bpi                        : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
c1                         : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
c2                         : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
f6                         : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
hdmipi                     : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
kg-omni1                   : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
ndwiki                     : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
proxy                      : ok=4    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
rtl433                     : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
steamos                    : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
v7                         : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
vm2                        : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
vm3                        : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
vm4                        : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
web                        : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
web2                       : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
wiki2                      : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
xh61v                      : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   

Fortunately, the column command can help with the formatting

tingo@kg-core2:/zs/tingo/personal/projects/2020/ansible_fbsd/infrastructure_home $ column -s, -t < os.csv
hostname  system   distribution  version  release
kg-vm2    FreeBSD  FreeBSD       12.4     12.4-RELEASE-p1
proxy     FreeBSD  FreeBSD       11.4     11.4-RELEASE
kg-v7     FreeBSD  FreeBSD       11.4     11.4-STABLE
kg-vm3    FreeBSD  FreeBSD       13.2     13.2-RELEASE-p1
wiki2     FreeBSD  FreeBSD       11.4     11.4-RELEASE-p9
kg-bpi    Linux    Debian        12.0     bookworm
kg-vm4    Linux    Debian        12.0     bookworm
kg-f6     FreeBSD  FreeBSD       11.1     11.1-STABLE
hdmipi    FreeBSD  FreeBSD       13.0     13.0-RELEASE
rtl433    Linux    Debian        10       buster
www       FreeBSD  FreeBSD       13.1     13.1-RELEASE-p1
kg-core1  FreeBSD  FreeBSD       13.2     13.2-RELEASE-p1
kg-core2  FreeBSD  FreeBSD       13.1     13.1-RELEASE-p6

that's all.