Skip to content
Find tables

Find tables with no delimiters

Find tables with no delimiters

Find the tables in text and in a tree of files, whatever their separators and column widths. A table is found by its token shape repeating row after row: a field is one token whatever its width, so a ragged table still repeats (shape).

$ cat data/rows.csv
id,host,bytes,ms
1,alpha,1024,12
2,beta,2048,19
3,gamma,4096,31
4,delta,8192,44
5,epsilon,16384,57
6,zeta,32768,73
$ cat data/notes.md
# Reading a directory

The walk reports what it found rather than what it was asked for. A filter that
silently drops a file reads exactly the same as a directory that never held one, and
the reader cannot tell the two apart afterwards.

Read a text’s regions

$ trex spectral --code-classify data/rows.csv
trex spectral (region classification: shape x spectral): 115 bytes, 1 regions
    [       0..115     ] table(p7)  id,host,bytes,ms 1,alpha,102

The period is in tokens: seven, a row’s four fields and three commas.

Find the files that are tables

A file’s kind is the region kind covering most of its bytes:

$ trex scan --files --texture data/
data/notes.md: prose
data/rows.csv: table, period 7

$ trex scan --files --texture table data/
data/rows.csv

Scan only the tables

The same filter narrows a scan of a tree:

$ trex scan '\N{>10000}' --texture table data/
data/rows.csv:6:11: "16384"
data/rows.csv:7:8: "32768"

!table, and -ExcludeTexture in PowerShell, drop the tables instead.