Linux Platform

column

Formater du texte en colonnes

éditeurtexteformatagetableau

Syntaxe

column [OPTIONS] [FICHIER...]

Options principales

OptionDescription
-tCreer un tableau avec des colonnes alignees
-s DELIMSpecifier le delimiteur d'entrée
-o DELIMSpecifier le delimiteur de sortie
-N NOMSDefinir les noms des colonnes
-JSortie au format JSON

Exemples

Formater un fichier CSV en tableau

$ cat services.csv
nom,port,statut
nginx,80,actif
postgres,5432,actif
redis,6379,arrête
 
$ column -t -s ',' services.csv
nom       port  statut
nginx     80    actif
postgres  5432  actif
redis     6379  arrête

Afficher la sortie d'une commande en colonnes

$ mount | column -t
/dev/sda1  on  /      type  ext4   (rw,relatime)
/dev/sda2  on  /home  type  ext4   (rw,relatime)
tmpfs      on  /tmp   type  tmpfs  (rw,nosuid)

Definir des noms de colonnes personnalisés

$ echo -e "web-01 192.168.1.10 actif\ndb-01 192.168.1.20 actif" | \
  column -t -N "SERVEUR,IP,STATUT"
SERVEUR  IP             STATUT
web-01   192.168.1.10   actif
db-01    192.168.1.20   actif

Convertir un tableau en JSON

$ echo -e "nom port\nnginx 80\nredis 6379" | column -t -N "nom,port" -J
{
   "table": [
      {"nom": "nginx", "port": "80"},
      {"nom": "redis", "port": "6379"}
   ]
}