TABLIFY(1p)

πŸ“¦
version 1.6.5 Β· 4 versions
, in ubuntu noble, ubuntu questing

πŸ’– 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 with no-headers, the list should be field numbers (starting at 1). otherwise, it should be field names.
  • -w, where=f<cmp>v β€” applies the cmp Perl operator to restrict output where field f matches the value v. 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 β€” use x as the field separator. the default is a tab, "\t".
  • --rs=x β€” use x as 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::RecordParser
  • Text::TabularDisplay
  • DBD::CSV
    • although I don't DBD::CSV this module, the idea was much the inspiration for this. I just didn't want to have to install DBI and DBD::CSV to get this kind of functionality. I think my interface is simpler. (and honestly? it ate. πŸ’…)

🌟 AUTHOR 🌟

Ken Youens-Clark <kclark@cpan.org>.


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