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         --strip-quotes      Strip " or ' around fields
17         -l|--list           List the fields in the file (for use with -f)
18         -f|--fields=f1[,f2] Show only fields in comma-separated list;
19                             when used in conjunction with "no-headers"
20                             the list should be field numbers (starting at 1);
21                             otherwise, should be field names
22         -w|where=f<cmp>v    Apply the "cmp" Perl operator to restrict output
23                             where field "f" matches the value "v";  acceptable
24                             operators include ==, eq, >, >=, <=, and =~
25         -v|--vertical       Show records vertically
26         --limit=n           Limit to first "n" records
27         --fs=x              Use "x" as the field separator
28                             (default is tab "\t")
29         --rs=x              Use "x" as the record separator
30                             (default is newline "\n")
31         --as-html           Create an HTML table instead of plain text
32

DESCRIPTION

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

EXAMPLES

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

SEE ALSO

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

AUTHOR

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