banner

For a list of BASHing data 2 blog posts see the index page.    RSS


csvlens: a delimited text file viewer for the terminal

I downloaded the latest csvlens (v.0.11.0) from its GitHub site as a ready-to-use, 8.7 MB executable and tested it on CSVs (comma and semicolon separated), TSVs and PSVs.

TL, DR: it works very well as a viewer!


Viewport. Like the less command, csvlens pages a file, so the beginnings of even gigantic files appear instantly in your terminal. The number of lines appearing will depend on your terminal's window and font settings, and for the screenshot below I've shrunk my terminal window for clarity. The launch command was csvlens -t obspts1.tsv, where the -t flag specified a tab as field delimiter.

csvlens1

As you can see, the viewport is neatly divided into a header box with fieldnames, a left-hand box with record numbers (the header line isn't counted) and a message box. The starting message has the filename and a locator for the currently selected record. My 2.9 GB test file "obspts1.tsv" has 4420969 records and 91 fields. Long data items are ellipsized. The header box, record-number box and message box are all frozen and won't disappear when you move through the file.


Navigation and selection. There's no man page for csvlens but the GitHub page lists some simple options and navigation commands. I use left and right arrow to move left and right, and Ctrl + left/right arrow will get me to the beginning or end of a record. For moving up and down I use down arrow, up arrow, Page Down, Page Up, End and Home. You can also enter "G" to get to the last record and "g" to get back to the first one. Entering a record number followed by "G" returns a viewport with the selected record at the top and highlighted.

Selection takes a little getting used to. You can select a row, a column or an individual data item by toggling with TAB. By default, rows are selected, then columns, then items-within-columns, then rows again, in that order. In the following series of screenshots, I first got to record 265 by entering "265G", and that selected the whole record. I then tabbed to get to column selection and right-arrowed to the "CLASS1" column. I tabbed again and down-arrowed to the "Aves" in record 270, and tabbed again to select that row.

csvlens2
csvlens3
csvlens4
csvlens5

Searching. Entering "/" takes you into "Find mode" and you can search for literals or regex. In the screenshot below, I was searching for the string "Moscal". csvlens moved to the first record (2571) containing that string, but not to the first column with it.

To find the string (which csvlens highlights), I first tabbed to select columns, then right-arrowed columns until I found the highlight, then entered ">" a few times to progressively increase the width of the "OBSERVER_TEXT" column. Note that the message box told me that the string was in column 57 of 91. This is because that column is the first one visible at the left as a result of my column-shifting, not because csvlens has identified that column as the first one with the target string.

csvlens6

Entering "n" takes you to the next result in "Find mode", and "N" to the previous result.

A possibly useful feature is that once you've found a data item of interest and selected it with the tabbing method, press Enter. csvlens exits and returns the full contents of the selected data item:

csvlens7

More... There are some other options listed on the GitHub readme page for csvlens. I'm finding the program mainly useful for viewing huge files before doing searching and other operations on the command line with other tools.


Next post:
2025-05-09   Two more tweaks for the ranger file manager


Last update: 2025-05-02
The blog posts on this website are licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License