Tabler
I’ve created a simple little program that should prove helpful for my scripts.
The concept is simple:
Key | Value |
---|---|
yt | www.youtube.co.uk |
g | www.4chan.org/g |
goog | www.google.co.uk |
Have a file with a key that is separated by spaces (or tabs) to it’s value.
When run, Tabler requires a table file as it’s first argument, and any subsequent argument is a “key” that it will try and match in the table file, then if any matches are found, it will print the value to standard output.
Now this leaves the fairly obvious point, why not just grep the line you want to match and then awk the second column?
Here are a few reasons.
Speed
Both tests are on the same text file with 10k lines of random values. Timing results of both (using the last key in the file):
time tabler test.txt 8r3KVHIpsg56w
RQl9eB1QwUQWy
real 0m0.002s
user 0m0.002s
sys 0m0.001s
time grep 8r3KVHIpsg56w test.txt | awk '{ print $2 }'
RQl9eB1QwUQWy
real 0m0.005s
user 0m0.005s
sys 0m0.004s
As you can see the difference in speed probably doesn’t matter for the vast majority of tasks, but if speed is your need, Tabler is able to to do the task 2.5 times faster.
Cross-platform
The issue with grep and awk it limited to unix-like systems.
Whilst only currently tested on Windows 10 and Arch Linux, in theory Tabler should be portable to almost any platform that has a C compiler. (Good luck finding one that doesn’t.)
Simple
Why not, does a simple job, that not a good enough reason? 😉