shawnw / tawk

Like awk, but using tcl as the scripting language.
MIT License
10 stars 0 forks source link

tawk - awk but in tcl

awk is a great tool for working with columnar data a line at a time, but the langauge itself is a bit limited. Usually when it's not quite powerful enough, I turn to perl. But... choice is good. Enter tawk, which uses tcl as the scripting language. It's designed to be very familiar to anyone coming from an awk background.

Running tawk

Much like awk:

tawk [OPTIONS] ['script'] [var=value | filename] ...

Reads from standard input if no filenames are given on command line.

Installing

Dependencies are tcl 8.6, and tcllib. Copy the tawk script to /usr/local/bin or wherever - it's a single, self-contained script.

Options

The language

Commands

tawk adds the following commands on top of basic tcl:

These are available as top-level commands.

These are available everywhere

Changes to existing commands

Variables

Most of these are lifted straight from awk names.

CSV Mode

If invoked with the -csv option, the output field separator (OFS) is set to comma instead of a space, and print joins its arguments with CSV escaping.

When reading fields, the default field separator (FS) if not explicitly set is a comma, and only single-character separators are supported. Lines are split by a CSV-aware parser - so commas in quoted fields don't count, unlike if just setting FS to a comma in normal mode. The CSVQUOTECHAR variable controls the character used to quote fields (Defaults to double quote, set by the -quotechar option.)

Also, the print command CSV-escapes its arguments, and gets reads a full CSV record, which may be multiple lines.