Desculpas pelo longo post.
Existem vários módulos perl que executam a formatação da tabela. Aqui está uma comparação de alguns deles. Os dados estão no arquivo data2. O snippet de script é:
# print-like-echo; print-line-with-visual-space.
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
FILE=${1-data2}
pl " Data file $FILE:"
head $FILE
pl " Results with column:"
column -s ':' -t $FILE
pl " Results from column | sed:"
column -s ':' -t < $FILE | sed -E 's/ ([^ ])/ | /g'
pl " Results of sed | column:"
sed 's/:/ | /g' $FILE | column -s ':' -t
./p4 $FILE
O código perl é de cerca de 30 linhas de perl (e alguns comentários) no arquivo p4. Isso exigirá que alguns módulos sejam instalados:
#!/usr/bin/env perl
# @(#) p4 Demonstrate various table formatters on password file.
use strict;
use warnings;
use Text::Table::Any;
my ( $rows, @a, @my_be, $back_end );
# Data rows from passwd-format file.
while (<>) {
chomp;
@a = split /:/;
push @$rows, [@a];
}
@my_be = ("Text::Table::Tiny");
# push @my_be, 'Text::Table::TinyColor';
# push @my_be, 'Text::Table::TinyColorWide';
# push @my_be, 'Text::Table::TinyWide';
push @my_be, 'Text::Table::Org';
push @my_be, 'Text::Table::CSV';
# push @my_be, 'Text::Table::HTML';
# push @my_be, 'Text::Table::HTML::DataTables';
push @my_be, 'Text::Table::Paragraph';
# push @my_be, 'Text::ANSITable';
push @my_be, 'Text::ASCIITable';
push @my_be, 'Text::FormatTable';
# push @my_be, 'Text::MarkdownTable';
push @my_be, 'Text::Table';
push @my_be, 'Text::TabularDisplay';
# push @my_be, 'Text::TestForError';
foreach $back_end (@my_be) {
print "\n\n----\n";
print " Backend table processor = $back_end\n";
print "\n";
print Text::Table::Any::table(
rows => $rows,
header_row => 1,
backend => $back_end,
);
}
Os resultados da execução dos dados ./s12 são:
-----
Data file data2:
login:password:UID:GID:name:home:shell
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
_applepay:*:260:260:applepay:/var/db/applepay:/usr/bin/false
_hidd:*:261:261:HID Service:/var/db/hidd:/usr/bin/false
-----
Results with column:
login password UID GID name home shell
daemon x 1 1 daemon /usr/sbin /usr/sbin/nologin
bin x 2 2 bin /bin /usr/sbin/nologin
_applepay * 260 260 applepay /var/db/applepay /usr/bin/false
_hidd * 261 261 HID Service /var/db/hidd /usr/bin/false
-----
Results from column | sed:
login | password | UID | GID | name | home | shell
daemon | x | 1 | 1 | daemon | /usr/sbin | /usr/sbin/nologin
bin | x | 2 | 2 | bin | /bin | /usr/sbin/nologin
_applepay | * | 260 | 260 | applepay | /var/db/applepay | /usr/bin/false
_hidd | * | 261 | 261 | HID | Service | /var/db/hidd | /usr/bin/false
-----
Results of sed | column:
login | password | UID | GID | name | home | shell
daemon | x | 1 | 1 | daemon | /usr/sbin | /usr/sbin/nologin
bin | x | 2 | 2 | bin | /bin | /usr/sbin/nologin
_applepay | * | 260 | 260 | applepay | /var/db/applepay | /usr/bin/false
_hidd | * | 261 | 261 | HID Service | /var/db/hidd | /usr/bin/false
----
Backend table processor = Text::Table::Tiny
+-----------+----------+-----+-----+-------------+------------------+-------------------+
| login | password | UID | GID | name | home | shell |
+-----------+----------+-----+-----+-------------+------------------+-------------------+
| daemon | x | 1 | 1 | daemon | /usr/sbin | /usr/sbin/nologin |
| bin | x | 2 | 2 | bin | /bin | /usr/sbin/nologin |
| _applepay | * | 260 | 260 | applepay | /var/db/applepay | /usr/bin/false |
| _hidd | * | 261 | 261 | HID Service | /var/db/hidd | /usr/bin/false |
+-----------+----------+-----+-----+-------------+------------------+-------------------+
----
Backend table processor = Text::Table::Org
| login | password | UID | GID | name | home | shell |
|-----------+----------+-----+-----+-------------+------------------+-------------------|
| daemon | x | 1 | 1 | daemon | /usr/sbin | /usr/sbin/nologin |
| bin | x | 2 | 2 | bin | /bin | /usr/sbin/nologin |
| _applepay | * | 260 | 260 | applepay | /var/db/applepay | /usr/bin/false |
| _hidd | * | 261 | 261 | HID Service | /var/db/hidd | /usr/bin/false |
----
Backend table processor = Text::Table::CSV
"login","password","UID","GID","name","home","shell"
"daemon","x","1","1","daemon","/usr/sbin","/usr/sbin/nologin"
"bin","x","2","2","bin","/bin","/usr/sbin/nologin"
"_applepay","*","260","260","applepay","/var/db/applepay","/usr/bin/false"
"_hidd","*","261","261","HID Service","/var/db/hidd","/usr/bin/false"
----
Backend table processor = Text::Table::Paragraph
login: daemon
password: x
UID: 1
GID: 1
name: daemon
home: /usr/sbin
shell: /usr/sbin/nologin
login: bin
password: x
UID: 2
GID: 2
name: bin
home: /bin
shell: /usr/sbin/nologin
login: _applepay
password: *
UID: 260
GID: 260
name: applepay
home: /var/db/applepay
shell: /usr/bin/false
login: _hidd
password: *
UID: 261
GID: 261
name: HID Service
home: /var/db/hidd
shell: /usr/bin/false
----
Backend table processor = Text::ASCIITable
.---------------------------------------------------------------------------------------.
| login | password | UID | GID | name | home | shell |
+-----------+----------+-----+-----+-------------+------------------+-------------------+
| daemon | x | 1 | 1 | daemon | /usr/sbin | /usr/sbin/nologin |
| bin | x | 2 | 2 | bin | /bin | /usr/sbin/nologin |
| _applepay | * | 260 | 260 | applepay | /var/db/applepay | /usr/bin/false |
| _hidd | * | 261 | 261 | HID Service | /var/db/hidd | /usr/bin/false |
'-----------+----------+-----+-----+-------------+------------------+-------------------'
----
Backend table processor = Text::FormatTable
login |password|UID|GID|name |home |shell
daemon |x |1 |1 |daemon |/usr/sbin |/usr/sbin/nologin
bin |x |2 |2 |bin |/bin |/usr/sbin/nologin
_applepay|* |260|260|applepay |/var/db/applepay|/usr/bin/false
_hidd |* |261|261|HID Service|/var/db/hidd |/usr/bin/false
----
Backend table processor = Text::Table
login password UID GID name home shell
daemon x 1 1 daemon /usr/sbin /usr/sbin/nologin
bin x 2 2 bin /bin /usr/sbin/nologin
_applepay * 260 260 applepay /var/db/applepay /usr/bin/false
_hidd * 261 261 HID Service /var/db/hidd /usr/bin/false
----
Backend table processor = Text::TabularDisplay
+-----------+----------+-----+-----+-------------+------------------+-------------------+
| login | password | UID | GID | name | home | shell |
+-----------+----------+-----+-----+-------------+------------------+-------------------+
| daemon | x | 1 | 1 | daemon | /usr/sbin | /usr/sbin/nologin |
| bin | x | 2 | 2 | bin | /bin | /usr/sbin/nologin |
| _applepay | * | 260 | 260 | applepay | /var/db/applepay | /usr/bin/false |
| _hidd | * | 261 | 261 | HID Service | /var/db/hidd | /usr/bin/false |
+-----------+----------+-----+-----+-------------+------------------+-------------------+
Uma característica interessante é que os módulos Text :: ASCIITable e Text :: Table justificam os campos de números.
Isso está em um sistema como:
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution : Debian 8.9 (jessie)
bash GNU bash 4.3.30
perl 5.20.2
Felicidades ... felicidades, drl