I have a script that gets data from multiple sources and I want to format its output to HTML table format.
Edited:
The format at the moment:
[Environment Name]
[Back end version]
[DB Version]
[event1 status] [event2 status] [event schema] [nodes] [node_no] [vpool] [ver] [node_ip]
The list at the moment:
grid-dev
BE version: 6.0
Database version: 10
DISABLED DISABLED dev_1 3 01 1 10.0.19-MariaDB 10.101.666.11:3306
grid-test
BE version: 7.0
Database version: 11
ENABLED ENABLED test_1 2 02 4 10.0.17-MariaDB 10.108.777.14:3306
grid-test
BE version: 7.0
Database version: 11
SLAVESIDE_DISABLE SLAVESIDE_DISABLE test_2 1 02 3 10.0.17-MariaDB 10.108.777.47:3306
grid-staging
BE version: 6.0
Database version: 10
DISABLED DISABLED staging_1 2 02 4 10.0.18-MariaDB 10.109.888.22:3306
and I want to format it to HTML table in something like this
ENVIRONMENT BACKEND_VERSION DB_VERSION EVENT1 EVENT2 SCHEMA NODES NODE_NO VPOOL VERSION IP
----------------------------------------------------------------------------------------------------------------------------------------------------------
grid-dev 6 10 DISABLED DISABLED dev_1 3 01 1 10.0.19-MariaDB 10.101.666.11:3306
grid-test 7 11 ENABLED ENABLED test_1 2 02 4 10.0.17-MariaDB 10.108.777.14:3306
grid-test 7 11 SLAVES... SLAVESI... test_2 2 01 3 10.0.17-MariaDB 10.108.777.47:3306
grid-staging 6 10 DISABLED DISABLED stag_1 2 02 4 10.0.18-MariaDB 10.109.888.22:3306
Is it possible to do it using bash script ? Any help will be appreciated I am new to bash and HTML so I am stuck.
My attemp using the code on the answer:
awk 'BEGIN{print "ENVIRONMENT BACKEND_VERSION DB_VERSION EVENT1 EVENT2 SCHEMA NODES NODE_NO VPOOL VERSION IP" } NF==1{env=$0; t=1; next;} t==1{t++; be=$3; next;} t==2{t++; db=$3; next;} t==3{printf "%s %s %s %s\n", env, be, db, $0; env="#";be="#";db="#";}' < "$output" | column -t | tr '#' ' ' >> "$dbstats"
The out put is
ENVIRONMENT BACKEND_VERSION DB_VERSION EVENT1 EVENT2 SCHEMA NODES NODE_NO VPOOL VERSION IP
grid-dev56.0 136 grid_dev Database version: 138
DISABLED DISABLED grid_systest 3 03 1 10.0.19-MariaDBgrid-systest56.0
Database version: 138
SLAVESIDE_DISABLED SLAVESIDE_DISABLED grid_systest 3 01 1 10.0.19-MariaDBgrid-systest56.0
Database version: 138
SLAVESIDE_DISABLED SLAVESIDE_DISABLED grid_systest 3 02 1 10.0.19-MariaDBgrid-staging56.0
Database version: 136
SLAVESIDE_DISABLED SLAVESIDE_DISABLED grid_staging 3 03 1 10.0.19-MariaDBgrid-staging56.0
Database version: 136
SLAVESIDE_DISABLED SLAVESIDE_DISABLED grid_staging 3 02 1 10.0.19-MariaDBgrid-staging56.0
Database version: 136
ENABLED ENABLED grid_staging 3 01 1 10.0.19-MariaDBgrid-production56.0
Database version: 136
SLAVESIDE_DISABLED SLAVESIDE_DISABLED grid_production 3 03 1 10.0.19-MariaDBgrid-production56.0
Database version: 136
SLAVESIDE_DISABLED SLAVESIDE_DISABLED grid_production 3 02 1 10.0.19-MariaDBgrid-production56.0
Database version: 136
DISABLED SLAVESIDE_DISABLED grid_production 3 01 1 10.0.19-MariaDB
Thanks