https://github.com/dkogan/vnlog Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + For + Enterprise + Teams + Startups + Education + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} dkogan / vnlog Public * Notifications * Fork 6 * Star 100 Process labelled tabular ASCII data using normal UNIX tools 100 stars 6 forks Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights dkogan/vnlog This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 3 branches 48 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/d] Use Git or checkout with SVN using the web URL. [gh repo clone dkogan] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @dkogan dkogan changelog bump ... beb7365 Jan 13, 2023 changelog bump beb7365 Git stats * 609 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time completions fixed typo in vnl-filter zsh completion Jun 28, 2022 lib Improved error messages when parsing legend in perl Aug 28, 2022 packaging minor documentation updates Jul 17, 2020 test removed python2 support Jan 13, 2023 .dir-locals.el guide elisp is more robust Jul 23, 2021 .gitattributes no diff for README.org; it is generated Jul 25, 2019 .gitignore .gitignore update Mar 12, 2018 Changes changelog bump Jan 13, 2023 GNUmakefile removed python2 support Jan 13, 2023 README.org readme Sep 3, 2022 README.template.org readme Sep 3, 2022 b64_cencode.c exported vnlog-flavored base64 encoder Jul 16, 2019 dji-tsla.tar.gz demo data available to download Jul 18, 2021 guide-1.svg docs have images instead of ascii plots Jul 18, 2021 guide-2.svg docs have images instead of ascii plots Jul 18, 2021 guide-3.svg docs Jul 18, 2021 guide-4.svg docs Jul 18, 2021 guide-5.svg docs Jul 18, 2021 vnl-align vnl-align: empty lines are treated like comments, and are preserved Aug 1, 2020 vnl-filter vnl-filter: documentation Jun 28, 2022 vnl-gen-header Avoid requiring String::ShellQuote just for a comment Aug 28, 2021 vnl-join I'm using $RealBin instead of $Bin in all the tools Aug 27, 2021 vnl-make-matrix #! lines reference '/usr/bin/env ...' to pacify *BSD May 30, 2020 vnl-sort I'm using $RealBin instead of $Bin in all the tools Aug 27, 2021 vnl-tail I'm using $RealBin instead of $Bin in all the tools Aug 27, 2021 vnl-ts I'm using $RealBin instead of $Bin in all the tools Aug 27, 2021 vnl-uniq I'm using $RealBin instead of $Bin in all the tools Aug 27, 2021 vnlog-base64.h removed unneeded #include Jul 16, 2019 vnlog.c vnlog_set_output_FILE() can take ctx==NULL for the global context Apr 15, 2020 vnlog.h vnlog_set_output_FILE() can take ctx==NULL for the global context Apr 15, 2020 View code [ ] Talk Summary Synopsis Build and installation Install on non-Debian boxes Description Format details Workflows and recipes Storing disjoint data One unified vnlog stream Several discrete vnlog streams Data statistics Powershell-style filtering of common shell commands C interface Basic usage Contexts Remaining APIs Base64 interface Python interface numpy interface Compatibility Caveats and bugs Manpages vnl-filter vnl-align vnl-sort vnl-join vnl-tail vnl-ts vnl-uniq vnl-gen-header vnl-make-matrix Repository Authors License and copyright README.org Talk I just gave a talk about this at SCaLE 17x. Here are the video of the talk and the "slides". Summary Vnlog ("vanilla-log") is a toolkit for manipulating tabular ASCII data with labelled fields using normal UNIX tools. If you regularly use awk and sort and uniq and others, these tools will make you infinitely more powerful. The vnlog tools extend, rather than replace the standard tooling, so minimal effort is required to learn and use these tools. Everything assumes a trivially simple log format: * A whitespace-separated table of ASCII human-readable text * A # character starts a comment that runs to the end of the line (like in many scripting languages) * The first line that begins with a single # (not ## or #!) is a legend, naming each column. This is required, and the field names that appear here are referenced by all the tools. * Empty fields reported as - This describes 99% of the format, with some extra details below. Example: #!/usr/bin/whatever # a b c 1 2 3 ## comment 4 5 6 Such data can be processed directly with almost any existing tool, and this toolkit allows the user to manipulate this data in a nicer way by relying on standard UNIX tools. The core philosophy is to avoid creating new knowledge as much as possible. Consequently, the vnlog toolkit relies heavily on existing (and familiar!) tools and workflows. As such, the toolkit is small, light, and has a very friendly learning curve. Synopsis I have two sets of historical stock data, from the start of 2018 until now (2018/11): < dji.vnl head -n 4 # Date Open High Low Close AdjClose Volume 2018-11-15 25061.48 25354.56 24787.79 25289.27 25289.27 383292840 2018-11-14 25388.08 25501.29 24935.82 25080.50 25080.50 384240000 2018-11-13 25321.21 25511.03 25193.78 25286.49 25286.49 339690000 And < tsla.vnl head -n 4 # Date Open High Low Close AdjClose Volume 2018-11-15 342.33 348.58 339.04 348.44 348.44 4486339 2018-11-14 342.70 347.11 337.15 344.00 344.00 5036300 2018-11-13 333.16 344.70 332.20 338.73 338.73 5448600 I can pull out the closing prices: < dji.vnl vnl-filter -p Close | head -n4 # Close 25289.27 25080.50 25286.49 vnl-filter is primarily a wrapper around awk or perl, allowing the user to reference columns by name. I can then plot the closing prices: < dji.vnl vnl-filter -p Close | feedgnuplot --lines --unset grid guide-1.svg Here I kept only the closing price column, so the x-axis is just the row index. The data was in reverse chronological order, so this plot is also in reverse chronological order. Let's fix that: < dji.vnl vnl-sort -k Date | vnl-filter -p Close | feedgnuplot --lines --unset grid guide-2.svg The vnl-sort tool (and most of the other vnl-xxx tools) are wrappers around the core tools already available on the system (such as sort, in this case). With the primary difference being reading/writing vnlog, and referring to columns by name. We now have the data in the correct order, but it'd be nice to see the actual dates on the x-axis. While we're at it, let's label the axes too: < dji.vnl vnl-filter -p Date,Close | head -n4 # Date Close 2018-11-15 25289.27 2018-11-14 25080.50 2018-11-13 25286.49 < dji.vnl vnl-sort -k Date | vnl-filter -p Date,Close | feedgnuplot --lines --unset grid --timefmt %Y-%m-%d --domain \ --xlabel 'Date' --ylabel 'Price ($)' guide-3.svg What was the highest value of the Dow-Jones index, and when did it happen? < dji.vnl vnl-sort -rgk Close | head -n2 | vnl-align # Date Open High Low Close AdjClose Volume 2018-10-03 26833.47 26951.81 26789.08 26828.39 26828.39 280130000 Alrighty. Looks like the high was in October. Let's zoom in on that month: < dji.vnl vnl-sort -k Date | vnl-filter 'Date ~ /2018-10/' -p Date,Close | feedgnuplot --lines --unset grid --timefmt %Y-%m-%d --domain \ --xlabel 'Date' --ylabel 'Price ($)' guide-4.svg OK. Is this thing volatile? What was the largest single-day gain? < dji.vnl vnl-filter -p '.,d=diff(Close)' | head -n4 | vnl-align # Date Open High Low Close AdjClose Volume d 2018-11-15 25061.48 25354.56 24787.79 25289.27 25289.27 383292840 - 2018-11-14 25388.08 25501.29 24935.82 25080.50 25080.50 384240000 -208.77 2018-11-13 25321.21 25511.03 25193.78 25286.49 25286.49 339690000 205.99 < dji.vnl vnl-filter -p '.,d=diff(Close)' | vnl-sort -rgk d | head -n2 | vnl-align # Date Open High Low Close AdjClose Volume d 2018-02-02 26061.79 26061.79 25490.66 25520.96 25520.96 522880000 1175.21 Whoa. So the best single-gain day was 2018-02-02: the dow gained 1175.21 points between closing on Feb 1 and Feb 2. But it actually lost ground that day! What if I looked at the difference between the opening and closing in a single day? < dji.vnl vnl-filter -p '.,d=Close-Open' | vnl-sort -rgk d | head -n2 | vnl-align # Date Open High Low Close AdjClose Volume d 2018-02-06 24085.17 24946.23 23778.74 24912.77 24912.77 823940000 827.6 I guess by that metric 2018-02-06 was better. Let's join the Dow-jones index data and the TSLA data, and let's look at them together: vnl-join --vnl-autosuffix dji.vnl tsla.vnl -j Date | head -n4 | vnl-align # Date Open_dji High_dji Low_dji Close_dji AdjClose_dji Volume_dji Open_tsla High_tsla Low_tsla Close_tsla AdjClose_tsla Volume_tsla 2018-11-15 25061.48 25354.56 24787.79 25289.27 25289.27 383292840 342.33 348.58 339.04 348.44 348.44 4486339 2018-11-14 25388.08 25501.29 24935.82 25080.50 25080.50 384240000 342.70 347.11 337.15 344.00 344.00 5036300 2018-11-13 25321.21 25511.03 25193.78 25286.49 25286.49 339690000 333.16 344.70 332.20 338.73 338.73 5448600 vnl-join --vnl-autosuffix dji.vnl tsla.vnl -j Date | vnl-filter -p '^Close' | head -n4 | vnl-align # Close_dji Close_tsla 25289.27 348.44 25080.50 344.00 25286.49 338.73 vnl-join --vnl-autosuffix dji.vnl tsla.vnl -j Date | vnl-filter -p '^Close' | feedgnuplot --domain --points --unset grid \ --xlabel 'DJI price ($)' --ylabel 'TSLA price ($)' guide-5.svg Huh. Apparently there's no obvious, strong correlation between TSLA and Dow-Jones closing prices. And we saw that with just a few shell commands, without dropping down into a dedicated analysis system. Build and installation vnlog is a part of Debian/buster and Ubuntu/cosmic (18.10) and later. On those boxes you can simply $ sudo apt install vnlog libvnlog-dev libvnlog-perl python3-vnlog to get the binary tools, the C API, the perl and python3 interfaces respectively. Install on non-Debian boxes Most of this is written in an interpreted language, so there's nothing to build or install, and you can run the tools directly from the source tree: $ git clone https://github.com/dkogan/vnlog.git $ cd vnlog $ ./vnl-filter ..... The python and perl libraries can be run from the tree by setting the PYTHONPATH and PERL5LIB environment variables respectively. For the C library, you should make, and then point your CFLAGS and LDLIBS and LD_LIBRARY_PATH to the local tree. If you do want to install to some arbitrary location to simplify the paths, do this: $ make $ PREFIX=/usr/local make install This will install all the components into /usr/local. Description Vnlog data is nicely readable by both humans and machines. Any time your application invokes printf() for either diagnostics or logging, consider writing out vnlog-formatted data. You retain human readability, but gain the power all the vnl-... tools provide. Vnlog tools are designed to be very simple and light. There's an ever-growing list of other tools that do vaguely the same thing. Some of these: * https://github.com/BurntSushi/xsv * https://csvkit.readthedocs.io/ * https://github.com/johnkerl/miller * https://github.com/eBay/tsv-utils-dlang * https://www.gnu.org/software/datamash/ * https://stedolan.github.io/jq/ * https://github.com/benbernard/RecordStream * https://github.com/dinedal/textql * https://www.visidata.org/ * http://harelba.github.io/q/ * https://github.com/BatchLabs/charlatan * https://github.com/dbohdan/sqawk Many of these provide facilities to run various analyses, and others focus on data types that aren't just a table (json for instance). Vnlog by contrast doesn't analyze anything, and targets the most trivial possible data format. This makes it very easy to run any analysis you like in any tool you like. The main envisioned use case is one-liners, and the tools are geared for that purpose. The above mentioned tools are much more powerful than vnlog, so they could be a better fit for some use cases. I claim that * 90% of the time you want to do simple things, and vnlog is a great fit for the task * If you really do need to do something complex, you shouldn't be in the shell writing oneliners anymore, and a fully-fledged analysis system (numpy, etc) is more appropriate In the spirit of doing as little as possible, the provided tools are wrappers around tools you already have and are familiar with. The provided tools are: * vnl-filter is a tool to select a subset of the rows/columns in a vnlog and/or to manipulate the contents. This is an awk wrapper where the fields can be referenced by name instead of index. 20-second tutorial: vnl-filter -p col1,col2,colx=col3+col4 'col5 > 10' --has col6 will read the input, and produce a vnlog with 3 columns: col1 and col2 from the input, and a column colx that's the sum of col3 and col4 in the input. Only those rows for which both col5 > 10 is true and that have a non-null value for col6 will be output. A null entry is signified by a single - character. vnl-filter --eval '{s += x} END {print s}' will evaluate the given awk program on the input, but the column names work as you would hope they do: if the input has a column named x, this would produce the sum of all values in this column. * vnl-sort, vnl-uniq, vnl-join, vnl-tail, vnl-ts are wrappers around the corresponding commandline tools. These work exactly as you would expect also: the columns can be referenced by name, and the legend comment is handled properly. These are wrappers, so all the commandline options those tools have "just work" (except options that don't make sense in the context of vnlog). As an example, vnl-tail -f will follow a log: data will be read by vnl-tail as it is written into the log (just like tail -f, but handling the legend properly). And you already know how to use these tools without even reading the manpages! Note: I use the Linux kernel and the tools from GNU Coreutils exclusively, but this all has been successfully tested on FreeBSD and OSX also. Please let me know if something doesn't work. * vnl-align aligns vnlog columns for easy interpretation by humans. The meaning is unaffected * Vnlog::Parser is a simple perl library to read a vnlog * vnlog is a simple python library to read a vnlog. Both python2 and python3 are supported * libvnlog is a C library to simplify writing a vnlog. Clearly all you really need is printf(), but this is useful if we have lots of columns, many containing null values in any given row, and/or if we have parallel threads writing to a log. In my usage I have hundreds of columns of sparse data, so this is handy * vnl-make-matrix converts a one-point-per-line vnlog to a matrix of data. I.e. $ cat dat.vnl # i j x 0 0 1 0 1 2 0 2 3 1 0 4 1 1 5 1 2 6 2 0 7 2 1 8 2 2 9 3 0 10 3 1 11 3 2 12 $ < dat.vnl vnl-filter -p i,x | vnl-make-matrix --outdir /tmp Writing to '/tmp/x.matrix' $ cat /tmp/x.matrix 1 2 3 4 5 6 7 8 9 10 11 12 All the tools have manpages that contain more detail. And more tools will probably be added with time. Format details The high-level description of the vnlog format from above is sufficient to read/write "normal" vnlog data, but there are a few corner cases that should be mentioned. To reiterate, the format description from above describes vnlog as: * A whitespace-separated table of ASCII human-readable text * A # character starts a comment that runs to the end of the line (like in many scripting languages) * The first line that begins with a single # (not ## or #!) is a legend, naming each column. This is required, and the field names that appear here are referenced by all the tools. * Empty fields reported as - For a few years now I've been using these tools myself, and supporting others as they were passing vnlog data around. In the process I've encountered some slightly-weird data, and patched the tools to accept it. So today the included vnlog tools are very permissive, and accept any vnlog data that can possibly be accepted. Other vnlog tools may not be quite as permissive, and may not be able to interpret "weird" data. Points of note, describing the included vnlog tools: * Leading and trailing whitespace is ignored. Everywhere. So this data file will be read properly, with the x column containing 1 and 3: # x y 1 2 3 4 * Empty (or whitespace-only) lines anywhere are ignored, and treated as a comment * An initial # comment without field names is treated as a comment, and we continue looking for the legend in the following lines. So this data file will be read properly: ## comment # # x y 1 2 3 4 * Trailing comments are supported, like in most scripting languages. So this data file will be read properly: # x y 1 2 # comment 3 4 * Field names are very permissive: anything that isn't whitespace is supported. So this data file will be read properly: # x y # 1+ - 1 2 3 4 5 11 12 13 14 15 We can pull out the # and 1+ and - columns: vnl-filter -p '#,1+,-' And we can even operate on them, if we use whitespace to indicate field boundaries: vnl-filter -p 'x=1+ + 5' Note that this implies that trailing comments in a legend line are not supported: the extra # characters will be used for field names. Field names containing =,= or === are currently not accepted by vnl-filter, but are accepted by the other tools (vnl-sort and such). I'll make vnl-filter able to work with those field names too, eventually, but as a user, the simplest thing to do is to not pass around data with such field names. * Duplicated labels are supported whenever possible. So # x y z z 1 2 3 4 11 12 13 14 will work just fine, unless we're operating on z. With this data, both of these commands work: vnl-filter -p x vnl-filter -p z Picking z selects both of the z columns. But neither of these commands can work with the non-unique z column: vnl-filter -p s=z+1 vnl-sort -k z Workflows and recipes Storing disjoint data A common use case is a complex application that produces several semi-related subsets of data at once. Example: a moving vehicle is reporting both its own position and the observed positions of other vehicles; at any given time any number of other vehicles may be observed. Two equivalent workflows are possible: * a single unified vnlog stream for all the data * several discrete vnlog streams for each data subset Both are valid approaches One unified vnlog stream Here the application produces a single vnlog that contains all the columns, from all the data subsets. In any given row, many of the columns will be empty (i.e. contain only - ). For instance, a row describing a vehicle own position will not have data about any observations, and vice versa. It is inefficient to store all the extra - but it makes many things much nicer, so it's often worth it. vnl-filter can be used to pull out the different subsets. Sample joint.vnl: # time x_self x_observation 1 10 - 2 20 - 2 - 100 3 30 - 3 - 200 3 - 300 Here we have 3 instances in time. We have no observations at time 1, one observation at time 2, and two observations at time 3. We can use vnl-filter to pull out the data we want: $ < joint.vnl vnl-filter -p time,self # time x_self 1 10 2 20 2 - 3 30 3 - 3 - If we only care about our own positions, the + modifier in picked columns in vnl-filter is very useful here: $ < joint.vnl vnl-filter -p time,+self # time x_self 1 10 2 20 3 30 $ < joint.vnl vnl-filter -p time,+observation # time x_observation 2 100 3 200 3 300 Note that the default is --skipempty, so if we're only looking at x_self for instance, then we don't even need to + modifier: $ < joint.vnl vnl-filter -p self # x_self 10 20 30 Also, note that the vnlog C interface works very nicely to produce these datafiles: * You can define lots and lots of columns, but only fill some of them before calling vnlog_emit_record(). The rest will be set to -. * You can create multiple contexts for each type of data, and you can populate them with data independently. And when calling vnlog_emit_record_ctx(), you'll get a record with data for just that context. Several discrete vnlog streams Conversely, the application can produce separate vnlog streams for each subset of data. Depending on what is desired, exactly, vnl-join can be used to re-join them: $ cat self.vnl # time x_self 1 10 2 20 3 30 $ cat observations.vnl # time x_observation 2 100 3 200 3 300 $ vnl-join -j time -a- self.vnl observations.vnl # time x_self x_observation 1 10 - 2 20 100 3 30 200 3 30 300 Data statistics A common need is to compute basic statistics from your data. Many of the alternative toolkits listed above provide built-in facilities to do this, but vnlog does not: it's meant to be unixy, where each tool has very limited scope. Thus you can either do this with awk like you would normally, or you can use other standalone tools to perform the needed computations. For instance, I can generate some data: $ seq 2 100 | awk 'BEGIN {print "# x"} {print log($1)}' > /tmp/log.vnl Then I can compute the mean with awk: $ < /tmp/log.vnl vnl-filter --eval '{sum += x} END {print sum/NR}' 3.67414 Or I can compute the mean (and other stuff) with a separate standalone tool: $ < /tmp/log.vnl ministat x +----------------------------------------------------------------------------+ | xx | | x xxxxxxx | | xx xxxxxxxxxxxx| | x x xxxxxxxxxxxxxxxxxxxxxxx| |x x x x x x x x x xx xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| | |_______________A____M___________| | +----------------------------------------------------------------------------+ N Min Max Median Avg Stddev x 99 0.693147 4.60517 3.93183 3.6741353 0.85656382 ministat is not a part of the vnlog toolkit, but the vnlog format is generic so it works just fine. Powershell-style filtering of common shell commands Everything about vnlog is generic and simple, so it's easy to use it to process data that wasn't originally meant to be used this way. For instance filtering the output of ls -l to report only file names and sizes, skipping directories, and sorting by file sizes: $ ls -l total 320 -rw-r--r-- 1 dima dima 5044 Aug 25 15:04 Changes -rw-r--r-- 1 dima dima 12749 Aug 25 15:04 Makefile -rw-r--r-- 1 dima dima 69789 Aug 25 15:04 README.org -rw-r--r-- 1 dima dima 33781 Aug 25 15:04 README.template.org -rw-r--r-- 1 dima dima 5359 Aug 25 15:04 b64_cencode.c drwxr-xr-x 4 dima dima 4096 Aug 25 15:04 completions drwxr-xr-x 3 dima dima 4096 Aug 25 15:04 lib drwxr-xr-x 3 dima dima 4096 Aug 25 15:04 packaging drwxr-xr-x 2 dima dima 4096 Aug 25 15:04 test -rwxr-xr-x 1 dima dima 5008 Aug 25 15:04 vnl-align -rwxr-xr-x 1 dima dima 56637 Aug 25 15:04 vnl-filter -rwxr-xr-x 1 dima dima 5678 Aug 25 15:04 vnl-gen-header -rwxr-xr-x 1 dima dima 29815 Aug 25 15:04 vnl-join -rwxr-xr-x 1 dima dima 3631 Aug 25 15:04 vnl-make-matrix -rwxr-xr-x 1 dima dima 8372 Aug 25 15:04 vnl-sort -rwxr-xr-x 1 dima dima 5822 Aug 25 15:04 vnl-tail -rwxr-xr-x 1 dima dima 4439 Aug 25 15:04 vnl-ts -rw-r--r-- 1 dima dima 559 Aug 25 15:04 vnlog-base64.h -rw-r--r-- 1 dima dima 8169 Aug 25 15:04 vnlog.c -rw-r--r-- 1 dima dima 12677 Aug 25 15:04 vnlog.h $ (echo '# permissions num_links user group size month day time name'; ls -l | tail -n +2) | vnl-filter 'permissions !~ "^d"' -p name,size | vnl-sort -gk size | vnl-align # name size vnlog-base64.h 559 vnl-make-matrix 3631 vnl-ts 4439 vnl-align 5008 Changes 5044 b64_cencode.c 5359 vnl-gen-header 5678 vnl-tail 5822 vnlog.c 8169 vnl-sort 8372 vnlog.h 12677 Makefile 12749 vnl-join 29815 README.template.org 33781 vnl-filter 56637 README.org 69789 With a bit of shell manipulation, these tools can be applied to a whole lot of different data streams that know nothing of vnlog. C interface Basic usage For most uses, vnlog files are simple enough to be generated with plain prints. But then each print statement has to know which numeric column we're populating, which becomes effortful with many columns. In my usage it's common to have a large parallelized C program that's writing logs with hundreds of columns where any one record would contain only a subset of the columns. In such a case, it's helpful to have a library that can output the log files. This is available. Basic usage looks like this: In a shell: vnl-gen-header 'int w' 'uint8_t x' 'char* y' 'double z' 'void* binary' > vnlog_fields_generated.h In a C program test.c: #include "vnlog_fields_generated.h" int main() { vnlog_emit_legend(); vnlog_set_field_value__w(-10); vnlog_set_field_value__x(40); vnlog_set_field_value__y("asdf"); vnlog_emit_record(); vnlog_set_field_value__z(0.3); vnlog_set_field_value__x(50); vnlog_set_field_value__w(-20); vnlog_set_field_value__binary("\x01\x02\x03", 3); vnlog_emit_record(); vnlog_set_field_value__w(-30); vnlog_set_field_value__x(10); vnlog_set_field_value__y("whoa"); vnlog_set_field_value__z(0.5); vnlog_emit_record(); return 0; } Then we build and run, and we get $ cc -o test test.c -lvnlog $ ./test # w x y z binary -10 40 asdf - - -20 50 - 0.2999999999999999889 AQID -30 10 whoa 0.5 - The binary field in base64-encoded. This is a rarely-used feature, but sometimes you really need to log binary data for later processing, and this makes it possible. So you 1. Generate the header to define your columns 2. Call vnlog_emit_legend() 3. Call vnlog_set_field_value__...() for each field you want to set in that row. 4. Call vnlog_emit_record() to write the row and to reset all fields for the next row. Any fields unset with a vnlog_set_field_value__...() call are written as null: - This is enough for 99% of the use cases. Things get a bit more complex if we have have threading or if we have multiple vnlog ouput streams in the same program. For both of these we use vnlog contexts. Contexts To support independent writing into the same vnlog (possibly by multiple threads; this is reentrant), each log-writer should create a context, and use it when talking to vnlog. The context functions will make sure that the fields in each context are independent and that the output records won't clobber each other: void child_writer( // the parent context also writes to this vnlog. Pass NULL to // use the global one struct vnlog_context_t* ctx_parent ) { struct vnlog_context_t ctx; vnlog_init_child_ctx(&ctx, ctx_parent); while(records) { vnlog_set_field_value_ctx__xxx(&ctx, ...); vnlog_set_field_value_ctx__yyy(&ctx, ...); vnlog_set_field_value_ctx__zzz(&ctx, ...); vnlog_emit_record_ctx(&ctx); } vnlog_free_ctx(&ctx); // required only if we have any binary fields } If we want to have multiple independent vnlog writers to different streams (with different columns and legends), we do this instead: file1.c: #include "vnlog_fields_generated1.h" void f(void) { // Write some data out to the default context and default output (STDOUT) vnlog_emit_legend(); ... vnlog_set_field_value__xxx(...); vnlog_set_field_value__yyy(...); ... vnlog_emit_record(); } file2.c: #include "vnlog_fields_generated2.h" void g(void) { // Make a new session context, send output to a different file, write // out legend, and send out the data struct vnlog_context_t ctx; vnlog_init_session_ctx(&ctx); FILE* fp = fopen(...); vnlog_set_output_FILE(&ctx, fp); vnlog_emit_legend_ctx(&ctx); ... vnlog_set_field_value__a(...); vnlog_set_field_value__b(...); ... vnlog_free_ctx(&ctx); // required only if we have any binary fields vnlog_emit_record(); } Note that it's the user's responsibility to make sure the new sessions go to a different FILE by invoking vnlog_set_output_FILE(). Furthermore, note that the included vnlog_fields_....h file defines the fields we're writing to; and if we have multiple different vnlog field definitions in the same program (as in this example), then the different writers must live in different source files. The compiler will barf if you try to #include two different vnlog_fields_....h files in the same source. Remaining APIs * vnlog_printf(...) and vnlog_printf_ctx(ctx, ...) write to a pipe like printf() does. This exists primarily for comments. * vnlog_clear_fields_ctx(ctx, do_free_binary) clears out the data in a context and makes it ready to be used for the next record. It is rare for the user to have to call this manually. The most common case is handled automatically (clearing out a context after emitting a record). One area where this is useful is when making a copy of a context: struct vnlog_context_t ctx1; // .... do stuff with ctx1 ... add data to it ... struct vnlog_context_t ctx2 = ctx1; // ctx1 and ctx2 now both have the same data, and the same pointers to // binary data. I need to get rid of the pointer references in ctx1 vnlog_clear_fields_ctx(&ctx1, false); * vnlog_free_ctx(ctx) frees memory for an vnlog context. Do this before throwing the context away. Currently this is only needed for context that have binary fields, but this should be called for all contexts anyway, in case this changes in a later revision Base64 interface The C interface supports writing base64-encoded binary data using Chris Venter's libb64. The base64-encoder used here was slightly modified: the output appears all on one line, making is suitable to appear in a vnlog field. If we're writing a vnlog with printf() directly without using the vnlog.h interface described above, we allow this modified base64 encoder to be invoked by itself. Usage: void* binary_buffer = ...; int binary_buffer_len = ...; char base64_buffer[vnlog_base64_dstlen_to_encode(binary_buffer_len)]; vnlog_base64_encode( base64_buffer, sizeof(base64_buffer), binary_buffer, binary_buffer_len ); Clearly the above example allocates the base64 buffer on the stack, so it's only suitable for small-ish data chunks. But if you have lots and lots of data, probably writing it as base64 into a vnlog isn't the best thing to do. Python interface Reading vnlog data into a python program is simple. The vnlog Python module provides three different ways to do that: 1. slurp the whole thing into a numpy array using the slurp() function. Basic usage: import vnlog log_numpy_array,list_keys,dict_key_index = \ vnlog.slurp(filename_or_fileobject) This parses out the legend, and then calls numpy.loadtxt(). Null data values (-) are not supported 2. Iterate through the records: vnlog class, used as an iterator. Basic usage: import vnlog for d in vnlog.vnlog(filename_or_fileobject): print(d['time'],d['height']) Null data values are represented as None 3. Parse incoming lines individually: vnlog class, using the parse() method. Basic usage: import vnlog parser = vnlog.vnlog() for l in file: parser.parse(l) d = parser.values_dict() if not d: continue print(d['time'],d['height']) Most of the time you'd use options 1 or 2 above. Option 3 is the most general, but also the most verbose numpy interface If we need to read data into numpy specifically, nicer tools are available than the generic vnlog Python module. The built-in numpy.loadtxt numpy.savetxt functions work well (with the caveat that numpy.loadtxt() should be followed by numpysane.atleast_dims(..., -2) to make sure that a data array of shape (Nrows,Ncols) is returned even if Nrows==1. For example to write to standard output a vnlog with fields a, b and c: numpy.savetxt(sys.stdout, array, fmt="%g", header="a b c") Note that numpy automatically adds the # to the header. To read a vnlog from a file on disk, do something like array = numpysane.atleast_dims(numpy.loadtxt('data.vnl'), -2) These functions know that # lines are comments, but don't interpret anything as field headers. That's easy to do, so I'm not providing any helper libraries. I might do that at some point, but in the meantime, patches are welcome. Compatibility I use GNU/Linux-based systems exclusively, but everything has been tested functional on FreeBSD and OSX in addition to Debian, Ubuntu and CentOS. I can imagine there's something I missed when testing on non-Linux systems, so please let me know if you find any issues. Caveats and bugs These tools are meant to be simple, so some things are hard requirements. A big one is that columns are whitespace-separated. There is no mechanism for escaping or quoting whitespace into a single field. I think supporting something like that is more trouble than it's worth. Manpages vnl-filter NAME vnl-filter - filters vnlogs to select particular rows, fields SYNOPSIS $ cat run.vnl # time x y z temperature 3 1 2.3 4.8 30 4 1.1 2.2 4.7 31 6 1 2.0 4.0 35 7 1 1.6 3.1 42 $ = 35' | vnl-align # time x y z temperature 6 1 2.0 4.0 35 7 1 1.6 3.1 42 $ 10' would select only those rows whose "size" column contains a value > 10. See the detailed description of matches expressions below for more detail. Context lines "vnl-filter" supports the context output options ("-A", "-B" and "-C") exactly like the "grep" tool. I.e to print out all rows whose "size" column contains a value > 10 *but also* include the 3 rows immediately before *and* after such matching rows, do this: vnl-filter -C3 'size > 10' "-B" reports the rows *before* matching ones and "-A" the rows *after* matching ones. "-C" reports both. Note that this applies *only* to *matches* expressions: records skipped because they fail "--has" or "--skipempty" are *not* included in contextual output. Backend choice By default, the parsing of arguments and the legend happens in perl, which then constructs a simple awk script, and invokes "mawk" to actually read the data and to process it. This is done because awk is lighter weight and runs faster, which is important because our data sets could be quite large. We default to "mawk" specifically, since this is a simpler implementation than "gawk", and runs much faster. If for whatever reason we want to do everything with perl, this can be requested with the "--perl" option. Special functions For convenience we support several special functions in any expression passed on to awk or perl (named expressions, matches expressions, "--eval" strings). These generally maintain some internal state, and vnl-filter makes sure that this state is consistent. Note that these are evaluated *after* "--skipcomments" and "--has". So any record skipped because of a "--has" expression, for instance, will *not* be considered in "prev()", "diff()" and so on. * rel(x) returns value of "x" relative to the first value of "x". For instance we might want to see the time or position relative to the start, not relative to some absolute beginning. Example: $ cat tst.vnl # time x 100 200 101 212 102 209 $ ) # read each line { chomp; next unless matches; # skip non-matching lines evalexpr(); } --function|--sub Evaluates the given expression as a function that can be used in other expressions. This is most useful when you want to print something that can't trivially be written as a simple expression. For instance: $ cat tst.vnl # s 1-2 3-4 5-6 $ < tst.vnl vnl-filter --function 'before(x) { sub("-.*","",x); return x }' \ --function 'after(x) { sub(".*-","",x); return x }' \ -p 'b=before(s),a=after(s)' # b a 1 2 3 4 5 6 See the CAVEATS section below if you're doing something sufficiently-complicated where you need this. --function-abs|--sub-abs Convenience option to add an absolute-value "abs()" function. This is only useful for awk programs (the default, no "--perl" given) since perl already provides "abs()" by default. --begin|--BEGIN Evaluates the given expression in the BEGIN {} block of the generated awk (or perl) program. --end|--END Evaluates the given expression in the END {} block of the generated awk (or perl) program. --[no]skipempty Do [not] skip records where all fields are blank. By default we *do* skip all empty records; to include them, pass "--noskipempty" --skipcomments Don't output non-legend comments --perl By default all procesing is performed by "mawk", but if for whatever reason we want perl instead, pass "--perl". Both modes work, but "mawk" is noticeably faster. "--perl" could be useful because it is more powerful, which could be important since a number of things pass commandline strings directly to the underlying language (named expressions, matches expressions, "--eval" strings). Note that while variables in perl use sigils, column references should *not* use sigils. To print the sum of all values in column "a" you'd do this in awk vnl-filter --eval '{suma += a} END {print suma}' and this in perl vnl-filter --perl --eval '{$suma += a} END {say $suma}' The perl strings are evaluated without "use strict" or "use warnings" so I didn't have to declare $suma in the example. With "--perl", empty strings ("-" in the vnlog file) are converted to "undef". --dumpexprs Used for debugging. This spits out all the final awk (or perl) program we run for the given commandline options and given input. This is the final program, with the column references resolved to numeric indices, so one can figure out what went wrong. --unbuffered Flushes each line after each print. This makes sure each line is output as soon as it is available, which is crucial for realtime output and streaming plots. --stream Synonym for "--unbuffered" CAVEATS This tool is very lax in its input validation (on purpose). As a result, columns with names like %CPU and "TIME+" do work (i.e. you can more or less feed in output from "top -b"). The downside is that shooting yourself in the foot is possible. This tradeoff is currently tuned to be very permissive, which works well for my use cases. I'd be interested in hearing other people's experiences. Potential pitfalls/unexpected behaviors: * All column names are replaced in all eval strings without regard to context. The earlier example that reports the sum of values in a column: "vnl-filter --eval '{suma += a} END {print suma}'" will work fine if we *do* have a column named "a" and do *not* have a column named "suma". But will not do the right thing if any of those are violated. For instance, if a column "a" doesn't exist, then "awk" would see "suma += a" instead of something like "suma += $5". "a" would be an uninitialized variable, which evaluates to 0, so the full "vnl-filter" command would not fail, but would print 0 instead. It's the user's responsibility to make sure we're talking about the right columns. The focus here was one-liners so hopefully nobody has so many columns, they can't keep track of all of them in their head. I don't see any way to resolve this without seriously impacting the scope of the tool, so I'm leaving this alone. * It is natural to use vnlog as a database. You can run queries with something like vnl-filter 'key == 5' This works. But unlike a real database this is clearly a linear lookup. With large data files, this would be significantly slower than the logarithmic searches provided by a real database. The meaning of "large" and "significant" varies, and you should test it. In my experience vnlog "databases" scale surprisingly well. But at some point, importing your data to something like sqlite is well worth it. * When substituting column names I match *either* a word-nonword transition ("\b") *or* a whitespace-nonword transition. The word boundaries is what would be used 99% of the time. But the keys may have special characters in them, which don't work with "\b". This means that whitespace becomes important: "1+%CPU" will not be parsed as expected, which is correct since "+%CPU" is also a valid field name. But "1+ %CPU" will be parsed correctly, so if you have weird field names, put the whitespace into your expressions. It'll make them more readable anyway. * Strings passed to "-p" are split on "," *except* if the "," is inside balanced "()". This makes it possible to say things like "vnl-filter --function 'f(a,b) { ... }' -p 'c=f(a,b)'". This is probably the right behavior, although some questionable looking field names become potentially impossible: "f(a" and "b)" *could* otherwise be legal field names, but you're probably asking for trouble if you do that. * Currently there're two modes: a pick/print mode and an "--eval" mode. Then there's also "--function", which adds bits of "--eval" to the pick/print mode, but it feels maybe insufficient. I don't yet have strong feelings about what this should become. Comments welcome vnl-align NAME vnl-align - aligns vnlog columns for easy interpretation by humans SYNOPSIS $ cat tst.vnl # w x y z -10 40 asdf - -20 50 - 0.300000 -30 10 whoa 0.500000 $ vnl-align tst.vnl # w x y z -10 40 asdf - -20 50 - 0.300000 -30 10 whoa 0.500000 DESCRIPTION The basic usage is vnl-align logfile The arguments are assumed to be the vnlog files. If no arguments are given, the input comes from STDIN. This is very similar to "column -t", but handles "#" lines properly: 1. The first "#" line is the legend. For the purposes of alignment, the leading "#" character and the first column label are treated as one column 2. All other "#" lines are output verbatim. vnl-sort NAME vnl-sort - sorts an vnlog file, preserving the legend SYNOPSIS $ cat a.vnl # a b AA 11 bb 12 CC 13 dd 14 dd 123 Sort lexically by a: $ 2. See below for details. Past that, everything "join" does is supported, so see that man page for detailed documentation. Note that all non-legend comments are stripped out, since it's not obvious where they should end up. Field names in the output By default, the field names in the output match those in the input. This is what you want most of the time. It is possible, however that a column name adjustment is needed. One common use case for this is if the files being joined have identically-named columns, which would produce duplicate columns in the output. Example: we fixed a bug in a program, and want to compare the results before and after the fix. The program produces an x-y trajectory as a function of time, so both the bugged and the bug-fixed programs produce a vnlog with a legend # time x y Joining this on "time" will produce a vnlog with a legend # time x y x y which is confusing, and *not* what you want. Instead, we invoke "vnl-join" as vnl-join --vnl-suffix1 _buggy --vnl-suffix2 _fixed -j time buggy.vnl fixed.vnl And in the output we get a legend # time x_buggy y_buggy x_fixed y_fixed Much better. Note that "vnl-join" provides several ways of specifying this. The above works *only* for 2-way joins. An alternate syntax is available for N-way joins, a comma-separated list. The same could be expressed like this: vnl-join -a- --vnl-suffix _buggy,_fixed -j time buggy.vnl fixed.vnl Finally, if passing in structured filenames, "vnl-join" can infer the desired syntax from the filenames. The same as above could be expressed even simpler: vnl-join --vnl-autosuffix -j time buggy.vnl fixed.vnl This works by looking at the set of passed in filenames, and stripping out the common leading and trailing strings. Sorting of input and output The GNU coreutils "join" tool expects sorted columns because it can then take only a single pass through the data. If the input isn't sorted, then we can use normal shell substitutions to sort it: $ vnl-join -j key <(vnl-sort -s -k key a.vnl) <(vnl-sort -s -k key b.vnl) For convenience "vnl-join" provides a "--vnl-sort" option. This allows the above to be equivalently expressed as $ vnl-join -j key --vnl-sort - a.vnl b.vnl The "-" after the "--vnl-sort" indicates that we want to sort the *input* only. If we also want to sort the output, pass the short codes "sort" accepts instead of the "-". For instance, to sort the input for "join" and to sort the output numerically, in reverse, do this: $ vnl-join -j key --vnl-sort rg a.vnl b.vnl The reason this shorthand exists is to work around a quirk of "join". The sort order is *assumed* by "join" to be lexicographical, without any way to change this. For "sort", this is the default sort order, but "sort" has many options to change the sort order, options which are sorely missing from "join". A real-world example affected by this is the joining of numerical data. If you have "a.vnl": # time a 8 a 9 b 10 c and "b.vnl": # time b 9 d 10 e Then you cannot use "vnl-join" directly to join the data on time: $ vnl-join -j time a.vnl b.vnl # time a b join: /dev/fd/4:3: is not sorted: 10 c join: /dev/fd/5:2: is not sorted: 10 e 9 b d 10 c e Instead you must re-sort both files lexicographically, *and* then (because you almost certainly want to) sort it back into numerical order: $ vnl-join -j time <(vnl-sort -s -k time a.vnl) <(vnl-sort -s -k time b.vnl) | vnl-sort -s -n -k time # time a b 9 b d 10 c e Yuck. The shorthand described earlier makes the interface part of this palatable: $ vnl-join -j time --vnl-sort n a.vnl b.vnl # time a b 9 b d 10 c e Note that the input sort is stable: "vnl-join" will invoke "vnl-sort -s". If you want a stable post-sort, you need to ask for it with "--vnl-sort s...". N-way joins The GNU coreutils "join" tool is inherently designed to join *exactly* two files. "vnl-join" extends this capability by chaining together a number of "join" invocations to produce a generic N-way join. This works exactly how you would expect with the following caveats: * Full outer joins are supported by passing "-a-", but no other "-a" option is supported. This is possible, but wasn't obviously worth the trouble. * "-v" is not supported. Again, this is possible, but wasn't obviously worth the trouble. * Similarly, "-o" is not supported. This is possible, but wasn't obviously worth the trouble, especially since the desired behavior can be obtained by post-processing with "vnl-filter". BUGS AND CAVEATS The underlying "sort" tool assumes lexicographic ordering, and matches fields purely based on their textual contents. This means that for the purposes of joining, 10, 10.0 and 1.0e1 are all considered different. If needed, you can normalize your keys with something like this: vnl-filter -p x='sprintf("%f",x)' COMPATIBILITY I use GNU/Linux-based systems exclusively, but everything has been tested functional on FreeBSD and OSX in addition to Debian, Ubuntu and CentOS. I can imagine there's something I missed when testing on non-Linux systems, so please let me know if you find any issues. SEE ALSO join(1) vnl-tail NAME vnl-tail - tail a log file, preserving the legend SYNOPSIS $ read_temperature | tee temp.vnl # temperature 29.5 30.4 28.3 22.1 ... continually produces data ... at the same time, in another terminal $ vnl-tail -f temp.vnl # temperature 28.3 22.1 ... outputs data as it comes in DESCRIPTION Usage: vnl-tail [options] logfile logfile logfile ... < logfile This tool runs "tail" on given vnlog files in various ways. "vnl-tail" is a wrapper around the GNU coreutils "tail" tool. Since this is a wrapper, most commandline options and behaviors of the "tail" tool are present; consult the tail(1) manpage for detail. The differences from GNU coreutils "tail" are * The input and output to this tool are vnlog files, complete with a legend * "-c" is not supported because vnlog really doesn't want to break up lines * "--zero-terminated" is not supported because vnlog assumes newline-separated records * By default we call the "tail" tool to do the actual work. If the underlying tool has a different name or lives in an odd path, this can be specified by passing "--vnl-tool TOOL" Past that, everything "tail" does is supported, so see that man page for detailed documentation. COMPATIBILITY I use GNU/Linux-based systems exclusively, but everything has been tested functional on FreeBSD and OSX in addition to Debian, Ubuntu and CentOS. I can imagine there's something I missed when testing on non-Linux systems, so please let me know if you find any issues. SEE ALSO tail(1) vnl-ts NAME vnl-ts - add a timestamp to a vnlog stream SYNOPSIS $ read_temperature # temperature 29.5 30.4 28.3 22.1 ... continually produces data at 1Hz $ read_temperature | vnl-ts -s %.s # time-rel temperature 0.013893 30.2 1.048695 28.6 2.105592 29.3 3.162873 22.0 ... DESCRIPTION Usage: vnl-ts [-i | -s] [-m] [--vnl-field t] format < pipe This tool runs "ts" on given vnlog streams. "vnl-ts" is a wrapper around the "ts" tool from Joey Hess's moreutils toolkit. Since this is a wrapper, most commandline options and behaviors of the "ts" tool are present; consult the ts(1) manpage for details. The differences from "ts" are * The input and output to this tool are vnlog files, complete with a legend * The format *must* be passed-in by the user; no default is assumed. * The given format *must not* contain whitespace, so that it fits a single vnlog field. * "-r" is not supported: it assumes input timestamps with whitespace, which is incompatible with vnlog * A "vnl-ts"-specific option "--vnl-field" is available to set the name of the new field. If omitted, a reasonable default will be used. * By default we call the "ts" tool to do the actual work. If the underlying tool has a different name or lives in an odd path, this can be specified by passing "--vnl-tool TOOL" Past that, everything "ts" does is supported, so see that man page for detailed documentation. COMPATIBILITY By default this calls the tool named "ts". At least on FreeBSD, it's called "moreutils-ts", so on such systems you should invoke "vnl-ts --vnl-tool moreutils-ts ..." I use GNU/Linux-based systems exclusively, but everything has been tested functional on FreeBSD and OSX in addition to Debian, Ubuntu and CentOS. I can imagine there's something I missed when testing on non-Linux systems, so please let me know if you find any issues. SEE ALSO ts(1) vnl-uniq NAME vnl-uniq - uniq a log file, preserving the legend SYNOPSIS $ cat colors.vnl # color blue yellow yellow blue yellow orange orange $ < colors.vnl | vnl-sort | vnl-uniq -c # count color 2 blue 2 orange 3 yellow DESCRIPTION Usage: vnl-uniq [options] < logfile This tool runs "uniq" on a given vnlog dataset. "vnl-uniq" is a wrapper around the GNU coreutils "uniq" tool. Since this is a wrapper, most commandline options and behaviors of the "uniq" tool are present; consult the uniq(1) manpage for detail. The differences from GNU coreutils "uniq" are * The input and output to this tool are vnlog files, complete with a legend * "--zero-terminated" is not supported because vnlog assumes newline-separated records * Only *one* input is supported (a file on the cmdline or data on standard input), and the output *always* goes to standard output. Specifying the output as a file on the commandline is not supported. * "--vnl-count NAME" can be given to name the "count" column. "-c" is still supported to add the default new column named "count", but if another name is wanted, "--vnl-count" does that. "--vnl-count" implies "-c" * In addition to the normal behavior of skipping fields at the start, "-f" and "--skip-fields" can take a negative argument to skip the *all but the last* N fields. For instance, to use only the one last field, pass "-f -1" or "--skip-fields=-1". * By default we call the "uniq" tool to do the actual work. If the underlying tool has a different name or lives in an odd path, this can be specified by passing "--vnl-tool TOOL" Past that, everything "uniq" does is supported, so see that man page for detailed documentation. COMPATIBILITY I use GNU/Linux-based systems exclusively, but everything has been tested functional on FreeBSD and OSX in addition to Debian, Ubuntu and CentOS. I can imagine there's something I missed when testing on non-Linux systems, so please let me know if you find any issues. SEE ALSO uniq(1) vnl-gen-header NAME vnl-gen-header - create definition for vnlog output from C SYNOPSIS $ vnl-gen-header 'int w' 'uint8_t x' 'char* y' 'double z' > vnlog_fields_generated.h DESCRIPTION We provide a simple C library to produce vnlog output. The fields this library outputs must be known at compile time, and are specified in a header created by this tool. Please see the vnlog documentation for instructions on how to use the library ARGUMENTS This tool needs to be given a list of field definitions. First we look at the commandline, and if the definitions are not available there, we look on STDIN. Each definition is a string "type name" (one def per argument on the commandline or per line on STDIN). If reading from STDIN, we ignore blank lines, and treat any line starting with "#" as a comment. Each def represents a single output field. Each such field spec in a C-style variable declaration with a type followed by a name. Note that these field specs contain whitespace, so each one must be quoted before being passed to the shell. The types can be basic scalars, possibly with set widths ("char", "double", "int", "uint32_t", "unsigned int", ...), a NULL-terminated string ("char*") or a generic chunk of binary data ("void*"). The names must consist entirely of letters, numbers or "_", like variables in C. vnl-make-matrix NAME vnl-make-matrix - create a matrix from a one-point-per-record vnlog SYNOPSIS $ cat /tmp/dat.vnl # i j x 0 0 1 0 1 2 0 2 3 1 0 4 1 1 5 1 2 6 2 0 7 2 1 8 2 2 9 3 0 10 3 1 11 3 2 12 $