TABLIFY(1p)
π NAME π
okay so, bestie, you've opened the manual page for tablify, and its whole entire job is to turn a delimited text file into a text table. that's the mission statement, that's the dream, no cap. β¨
(you found it in the User Contributed Perl Documentation part of the world, and the page is filed under TABLIFY(1p) π)
π¦ SYNOPSIS π¦
tablify [options] file
Options, speedrun edition (the full tea is down in OPTIONS, keep scrolling π):
-h,--helpβ Show help-c,--commentβ Define the beginning of a (single-line) comment-n,--no-headersβ Assume first line is data, not headers--no-pagerβ Do not use$ENV{'PAGER'}even if defined--strip-quotesβ Strip"or'around fields-l,--listβ List the fields in the file (for use with-f)-f,--fields=f1[,f2]β Show only fields in comma-separated list-w,where=f<cmp>vβ Restrict output where a field matches a value-v,--verticalβ Show records vertically-i,--limit=nβ Limit to given number of records--fs=xβ Field separator--rs=xβ Record separator--as-htmlβ Create an HTML table instead of plain text--headersβ Comma-separated list of names matching the number of columns
β¨ OPTIONS β¨
okay here's every single knob and dial, fr fr. nothing skipped, nothing merged, this is the complete set π«Ά
-h,--helpβ shows you the help. that's the whole personality. π-c,--commentβ you tell it what marks the start of a comment. heads up: it's a single-line comment situation, not a block thing.-n,--no-headersβ assume the first line is data, not headers. bold move, respect.--no-pagerβ do not use$ENV{'PAGER'}even if it's defined. like, even though it's right there being defined and everything. nope. π--strip-quotesβ peels the"or'off around fields.-l,--listβ lists the fields in the file. it's built to be used with-f, they're a duo π«Ά-f,--fields=f1[,f2]β show only the fields in that comma-separated list. and here's the plot twist: when you use it together withno-headers, the list should be field numbers (starting at 1). otherwise, it should be field names.-w,where=f<cmp>vβ applies thecmpPerl operator to restrict output where fieldfmatches the valuev. the operators it will accept are==,eq,>,>=,<=, and=~.-v,--verticalβ show records vertically. for when your table is doing too much horizontally π-i,--limit=nβ caps it at the given number of records.--fs=xβ usexas the field separator. the default is a tab,"\t".--rs=xβ usexas the record separator. the default is a newline,"\n".--as-htmlβ build an HTML table instead of plain text. glow up π--headersβ a comma-separated list of names matching the number of columns.
πΈ DESCRIPTION πΈ
so what is this script even. it's essentially a quick way to parse a delimited text file and view it as a nice ASCII table. and the way that you can select only certain fields, drop in a where clause so you only pull records where a field matches some value, and use the limit to only see some of the output β you almost have a mini-database front-end for a simple text file. iconic behaviour, honestly. π
π EXAMPLES π
let's get into it. given a data file like this:
name,rank,serial_no,is_living,age
George,General,190293,0,64
Dwight,General,908348,0,75
Attila,Hun,,0,56
Tojo,Emporor,,0,87
Tommy,General,998110,1,54
π¦ finding your fields
to find the fields you can reference, use the list option:
$ tablify --fs ',' -l people.dat
+-----------+-----------+
| Field No. | Field |
+-----------+-----------+
| 1 | name |
| 2 | rank |
| 3 | serial_no |
| 4 | is_living |
| 5 | age |
+-----------+-----------+
β¨ picking just some columns
to extract just the name and serial numbers, use the fields option:
$ tablify --fs ',' -f name,serial_no people.dat
+--------+-----------+
| name | serial_no |
+--------+-----------+
| George | 190293 |
| Dwight | 908348 |
| Attila | |
| Tojo | |
| Tommy | 998110 |
+--------+-----------+
5 records returned
π ranges, yes ranges
to extract the first through third fields and the fifth field (where field numbers start at "1" β tip: use the list option to quickly determine field numbers), use this syntax for fields:
$ tablify --fs ',' -f 1-3,5 people.dat
+--------+---------+-----------+------+
| name | rank | serial_no | age |
+--------+---------+-----------+------+
| George | General | 190293 | 64 |
| Dwight | General | 908348 | 75 |
| Attila | Hun | | 56 |
| Tojo | Emporor | | 87 |
| Tommy | General | 998110 | 54 |
+--------+---------+-----------+------+
5 records returned
π₯ where clauses go crazy
to select only the ones with six serial numbers, use a where clause:
$ tablify --fs ',' -w 'serial_no=~/^\d{6}$/' people.dat
+--------+---------+-----------+-----------+------+
| name | rank | serial_no | is_living | age |
+--------+---------+-----------+-----------+------+
| George | General | 190293 | 0 | 64 |
| Dwight | General | 908348 | 0 | 75 |
| Tommy | General | 998110 | 1 | 54 |
+--------+---------+-----------+-----------+------+
3 records returned
to find Dwight's record, you would do this:
$ tablify --fs ',' -w 'name eq "Dwight"' people.dat
+--------+---------+-----------+-----------+------+
| name | rank | serial_no | is_living | age |
+--------+---------+-----------+-----------+------+
| Dwight | General | 908348 | 0 | 75 |
+--------+---------+-----------+-----------+------+
1 record returned
to find the name of all the people with a serial number who are living:
$ tablify --fs ',' -f name -w 'is_living==1' -w 'serial_no>0' people.dat
+-------+
| name |
+-------+
| Tommy |
+-------+
1 record returned
π piping it in
to filter outside of program and simply format the results, use "-" as the last argument to force reading of STDIN (and probably assume no headers):
$ grep General people.dat | tablify --fs ',' -f 1-3 --no-headers -
+---------+--------+--------+
| Field1 | Field2 | Field3 |
+---------+--------+--------+
| General | 190293 | 0 |
| General | 908348 | 0 |
| General | 998110 | 1 |
+---------+--------+--------+
3 records returned
when dealing with data lacking field names, you can specify "no-headers" and then refer to fields by number (starting at one), e.g.:
$ tail -5 people.dat | tablify --fs ',' --no-headers -w '3 eq "General"' -
+--------+---------+--------+--------+--------+
| Field1 | Field2 | Field3 | Field4 | Field5 |
+--------+---------+--------+--------+--------+
| George | General | 190293 | 0 | 64 |
| Dwight | General | 908348 | 0 | 75 |
| Tommy | General | 998110 | 1 | 54 |
+--------+---------+--------+--------+--------+
3 records returned
π vertical mode, for the wide files
if your file has many fields which are hard to see across the screen, consider using the vertical display with "-v" or "--vertical", e.g.:
$ tablify --fs ',' -v --limit 1 people.dat
************ Record 1 ************
name: George
rank: General
serial_no: 190293
is_living: 0
age : 64
1 record returned
π SEE ALSO π
Text::RecordParserText::TabularDisplayDBD::CSV- although I don't
DBD::CSVthis module, the idea was much the inspiration for this. I just didn't want to have to installDBIandDBD::CSVto get this kind of functionality. I think my interface is simpler. (and honestly? it ate. π )
- although I don't
π AUTHOR π
Ken Youens-Clark <kclark@cpan.org>.
π LICENSE AND COPYRIGHT π
Copyright (C) 2006-10 Ken Youens-Clark. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
bestie that's a real GPL v2 situation up there, no joke β no warranty, none, zero. read the license, it's giving legal main character energy π
and that's the whole page, babes β this one's from perl v5.36.0, dated 2022-10-14, and it's filed as TABLIFY(1p). go make some pretty tables π
π¦ where this page comes from
- ubuntu noble: libtext-recordparser-perl 1.6.5-4 Β· GPL-2.0-only
- ubuntu questing: libtext-recordparser-perl 1.6.5-4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms