Create table using tbl command

Hi,

I required the output like attached:

I tried using the below command and i'm getting error:

file with data:
.TS
box;
cB s s
c|c|c
PO Download statistics - Host to SOM
Time;Receive Time;Processing Time;PO count
4.30 AM OMHPO File;Tue Feb 21 04:39:55 EST 2012;Tue Feb 21 05:38:58 EST 2012;17508
.TE

Command:
tbl file_name | troff

Please help me on this.

Hi.

Here is one solution that seems to match your attachment:

#!/usr/bin/env bash

# @(#) s2	Demonstrate table generation with tbl.

pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C tbl groff

FILE=${1-data1}

pl " Input file $FILE:"
cat $FILE

pl " Results:"
tbl $FILE |
groff -T ascii

exit 0

producing:

% ./s2

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
bash GNU bash 3.2.39
tbl GNU tbl (groff) version 1.18.1
groff GNU groff version 1.18.1

-----
 Input file data1:
.TS
tab(;) allbox;
c s s s
l l l l.
PO Download statistics - Host to SOM
Time;Receive Time;Processing Time;PO count
4.30 AM OMHPO File;Tue Feb 21 04:39:55 EST 2012;Tue Feb 21 05:38:58 EST 2012;17508
.TE

-----
 Results:
grotty:data1:7: character above first line discarded
+--------------------------------------------------------------------------------------------+
|                           PO Download statistics - Host to SOM                             |
+-------------------+------------------------------+------------------------------+----------+
|Time               | Receive Time                 | Processing Time              | PO count |
+-------------------+------------------------------+------------------------------+----------+
|4.30 AM OMHPO File | Tue Feb 21 04:39:55 EST 2012 | Tue Feb 21 05:38:58 EST 2012 | 17508    |
+-------------------+------------------------------+------------------------------+----------+

Trailing empty lines from [gn]roff were omitted.

Best wishes ... cheers, drl

Hi drl. Sorry for the late reply. I m using K shell and I'm not sure about the commands you have used.

Is it possible to embed this code in the middle of my script which generates the data required for table?

I just tried
tbl $File
for the format u mentioned but didn't work.

Thanks for your help.

Hi.

The code in the earlier script was designed to process the first parameter as the file containing the tbl markup. This is more specific and uses ksh (which for this purpose is not critical):

#!/usr/bin/env ksh

# @(#) s3	Demonstrate table generation with tbl.

pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C tbl groff


pl " Input file t1:"
cat t1

pl " Results:"
tbl t1 |
groff -T ascii

exit 0

producing:

% ./s3

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
ksh 93s+
tbl GNU tbl (groff) version 1.18.1
groff GNU groff version 1.18.1

-----
 Input file t1:
.TS
tab(;) allbox;
c s s s
l l l l.
PO Download statistics - Host to SOM
Time;Receive Time;Processing Time;PO count
4.30 AM OMHPO File;Tue Feb 21 04:39:55 EST 2012;Tue Feb 21 05:38:58 EST 2012;17508
.TE

-----
 Results:
grotty:t1:7: character above first line discarded
+--------------------------------------------------------------------------------------------+
|                           PO Download statistics - Host to SOM                             |
+-------------------+------------------------------+------------------------------+----------+
|Time               | Receive Time                 | Processing Time              | PO count |
+-------------------+------------------------------+------------------------------+----------+
|4.30 AM OMHPO File | Tue Feb 21 04:39:55 EST 2012 | Tue Feb 21 05:38:58 EST 2012 | 17508    |
+-------------------+------------------------------+------------------------------+----------+

Best wishes ... cheers, drl

1 Like