1TABLIFY(1)            User Contributed Perl Documentation           TABLIFY(1)
2
3
4

NAME

6       tablify - turn a delimited text file into a text table
7

SYNOPSIS

9         tablify [options] file
10
11       Options:
12
13         -h⎪--help           Show help
14         --no-headers        Assume first line is data, not headers
15         --no-pager          Do not use $ENV{'PAGER'} even if defined
16         -l⎪--list           List the fields in the file (for use with -f)
17         -f⎪--fields=f1[,f2] Show only fields in comma-separated list;
18                             when used in conjunction with "no-headers"
19                             the list should be field numbers (starting at 1);
20                             otherwise, should be field names
21         -w⎪where=f<cmp>v    Apply the "cmp" Perl operator to restrict output
22                             where field "f" matches the value "v";  acceptable
23                             operators include ==, eq, >, >=, <=, and =~
24         -v⎪--vertical       Show records vertically
25         --limit=n           Limit to first "n" records
26         --fs=x              Use "x" as the field separator
27                             (default is tab "\t")
28         --rs=x              Use "x" as the record separator
29                             (default is newline "\n")
30         --as-html           Create an HTML table instead of plain text
31

DESCRIPTION

33       This script is essentially a quick way to parse a delimited text file
34       and view it as a nice ASCII table.  By selecting only certain fields,
35       employing a where clause to only select records where a field matches
36       some value, and using the limit to only see some of the output, you
37       almost have a mini-database front-end for a simple text file.
38

EXAMPLES

40       Given a data file like this:
41
42         name,rank,serial_no,is_living,age
43         George,General,190293,0,64
44         Dwight,General,908348,0,75
45         Attila,Hun,,0,56
46         Tojo,Emporor,,0,87
47         Tommy,General,998110,1,54
48
49       To find the fields you can reference, use the list option:
50
51         $ tablify --fs ',' -l people.dat
52         +-----------+-----------+
53         ⎪ Field No. ⎪ Field     ⎪
54         +-----------+-----------+
55         ⎪ 1         ⎪ name      ⎪
56         ⎪ 2         ⎪ rank      ⎪
57         ⎪ 3         ⎪ serial_no ⎪
58         ⎪ 4         ⎪ is_living ⎪
59         ⎪ 5         ⎪ age       ⎪
60         +-----------+-----------+
61
62       To extract just the name and serial numbers, use the fields option:
63
64         $ tablify --fs ',' -f name,serial_no people.dat
65         +--------+-----------+
66         ⎪ name   ⎪ serial_no ⎪
67         +--------+-----------+
68         ⎪ George ⎪ 190293    ⎪
69         ⎪ Dwight ⎪ 908348    ⎪
70         ⎪ Attila ⎪           ⎪
71         ⎪ Tojo   ⎪           ⎪
72         ⎪ Tommy  ⎪ 998110    ⎪
73         +--------+-----------+
74         5 records returned
75
76       To extract the first through third fields and the fifth field (where
77       field numbers start at "1" -- tip: use the list option to quickly
78       determine field numbers), use this syntax for fields:
79
80         $ tablify --fs ',' -f 1-3,5 people.dat
81         +--------+---------+-----------+------+
82         ⎪ name   ⎪ rank    ⎪ serial_no ⎪ age  ⎪
83         +--------+---------+-----------+------+
84         ⎪ George ⎪ General ⎪ 190293    ⎪ 64   ⎪
85         ⎪ Dwight ⎪ General ⎪ 908348    ⎪ 75   ⎪
86         ⎪ Attila ⎪ Hun     ⎪           ⎪ 56   ⎪
87         ⎪ Tojo   ⎪ Emporor ⎪           ⎪ 87   ⎪
88         ⎪ Tommy  ⎪ General ⎪ 998110    ⎪ 54   ⎪
89         +--------+---------+-----------+------+
90         5 records returned
91
92       To select only the ones with six serial numbers, use a where clause:
93
94         $ tablify --fs ',' -w 'serial_no=~/^\d{6}$/' people.dat
95         +--------+---------+-----------+-----------+------+
96         ⎪ name   ⎪ rank    ⎪ serial_no ⎪ is_living ⎪ age  ⎪
97         +--------+---------+-----------+-----------+------+
98         ⎪ George ⎪ General ⎪ 190293    ⎪ 0         ⎪ 64   ⎪
99         ⎪ Dwight ⎪ General ⎪ 908348    ⎪ 0         ⎪ 75   ⎪
100         ⎪ Tommy  ⎪ General ⎪ 998110    ⎪ 1         ⎪ 54   ⎪
101         +--------+---------+-----------+-----------+------+
102         3 records returned
103
104       To find Dwight's record, you would do this:
105
106         $ tablify --fs ',' -w 'name eq "Dwight"' people.dat
107         +--------+---------+-----------+-----------+------+
108         ⎪ name   ⎪ rank    ⎪ serial_no ⎪ is_living ⎪ age  ⎪
109         +--------+---------+-----------+-----------+------+
110         ⎪ Dwight ⎪ General ⎪ 908348    ⎪ 0         ⎪ 75   ⎪
111         +--------+---------+-----------+-----------+------+
112         1 record returned
113
114       To find the name of all the people with a serial number who are living:
115
116         $ tablify --fs ',' -f name -w 'is_living==1' -w 'serial_no>0' people.dat
117         +-------+
118         ⎪ name  ⎪
119         +-------+
120         ⎪ Tommy ⎪
121         +-------+
122         1 record returned
123
124       To filter outside of program and simply format the results, use "-" as
125       the last argument to force reading of STDIN (and probably assume no
126       headers):
127
128         $ grep General people.dat ⎪ tablify --fs ',' -f 1-3 --no-headers -
129         +---------+--------+--------+
130         ⎪ Field1  ⎪ Field2 ⎪ Field3 ⎪
131         +---------+--------+--------+
132         ⎪ General ⎪ 190293 ⎪ 0      ⎪
133         ⎪ General ⎪ 908348 ⎪ 0      ⎪
134         ⎪ General ⎪ 998110 ⎪ 1      ⎪
135         +---------+--------+--------+
136         3 records returned
137
138       When dealing with data lacking field names, you can specify "no-head‐
139       ers" and then refer to fields by number (starting at one), e.g.:
140
141         $ tail -5 people.dat ⎪ tablify --fs ',' --no-headers -w '3 eq "General"' -
142         +--------+---------+--------+--------+--------+
143         ⎪ Field1 ⎪ Field2  ⎪ Field3 ⎪ Field4 ⎪ Field5 ⎪
144         +--------+---------+--------+--------+--------+
145         ⎪ George ⎪ General ⎪ 190293 ⎪ 0      ⎪ 64     ⎪
146         ⎪ Dwight ⎪ General ⎪ 908348 ⎪ 0      ⎪ 75     ⎪
147         ⎪ Tommy  ⎪ General ⎪ 998110 ⎪ 1      ⎪ 54     ⎪
148         +--------+---------+--------+--------+--------+
149         3 records returned
150
151       If your file has many fields which are hard to see across the screen,
152       consider using the vertical display with "-v" or "--vertical", e.g.:
153
154         $ tablify --fs ',' -v --limit 1 people.dat
155         ************ Record 1 ************
156              name: George
157              rank: General
158         serial_no: 190293
159         is_living: 0
160              age : 64
161
162         1 record returned
163

SEE ALSO

165       * Text::RecordParser
166       * Text::TabularDisplay
167       * DBD::CSV
168           Although I don't DBD::CSV this module, the idea was much the inspi‐
169           ration for this.  I just didn't want to have to install DBI and
170           DBD::CSV to get this kind of functionality.  I think my interface
171           is simpler.
172

AUTHOR

174       Ken Youens-Clark <kclark@cpan.org>.
175
177       Copyright (C) 2006 Ken Youens-Clark.  All rights reserved.
178
179       This program is free software; you can redistribute it and/or modify it
180       under the terms of the GNU General Public License as published by the
181       Free Software Foundation; version 2.
182
183       This program is distributed in the hope that it will be useful, but
184       WITHOUT ANY WARRANTY; without even the implied warranty of MER‐
185       CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
186       Public License for more details.
187
188
189
190perl v5.8.8                       2007-05-17                        TABLIFY(1)
Impressum