Column command in Linux (formatted in column, CSV or JSON)
The column command on Linux can actually save a developer a lot of time. It allows you to format a file or the output of a command in columns, CSV (separated by a comma) or JSON.
This actually saves a lot of time on data transformation.
Take, for example, the /etc/passwd file containing the system’s users, with the fields separated by colons:
The column command can be used to read the contents of this file and separate it into columns:
games x 5 60 games /usr/games /bin/false
man x 6 12 man /var/cache/man /bin/false The column command can also be used to view a CVS comma separated file:
This can be useful to view this type of file without the need for an Excel or similar one.
In some distributions, the column command makes it possible to export the data in JSON format, using the “-J” option, followed by the column names:
{“login”: “mail”, “password”: “x”, “uid”: “8”, “guid”: “12”, “name”: “mail”, “home”: “/var/spool/mail”, “shell”: “/sbin/nologin”},
]
} This command can be used in conjunction with any system command to generate JSON files.
See for example how easy it is to generate a list of files from a directory in JSON:
{” file”: “certbot-auto”},
{“file”: “certificate”},
]
} In this example, the output of the ls command, with the -1 option that lists only the files one per line, was transformed by the column command into a JSON file with a column called FILE, in the FILES table.
Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it?
Share