AWK It

AWK it! allows you to see AWK output as you are typing the script; it sends selected region to awk and uses yasnippet as interactive UI.

You can get the latest version here: Lisp:awk-it.el

Suggestions, questions & bugs: isikacek@gmail.com (Igor Sikaček)

There are 3 modes of AWK code: simplified syntax(default, see below), single line AWK syntax (regular AWK syntax but only inside the default match) and raw AWK syntax(full AWK code). AWK it! can transfrom code from one mode to another(not perfect, but it will make an effort) and there is also support for multiple lines. Data is expanded with selected yasnippet expand keybinding.

Simplest usage is selecting region and running M-x awk-it. Default field separator is space. AWK it! matches every non empty row in region ($0 !~ /^$/).

After invoking command buffer will change to show the following interface:

    Data: <First line with most fields>
    AWK pattern: <AWK code; may be multiple lines without extra formatting>
    <AWK output>

Example:

From:

    John 26 London
    Mark 27 Seattle 50
    Scott 26 Sydney

to (ignoring the extra field in example pattern):

    Data: Mark 27 Seattle 50
    AWK pattern: <person name="$1" age="$2">
        <location>$3</location>
    </person>
    <person name="John" age="26">
        <location>London</location>
    </person>
    <person name="Mark" age="27">
        <location>Seattle</location>
    </person>
    <person name="Scott" age="26">
        <location>Sydney</location>
    </person>

and after expansion:

    <person name="John" age="26">
        <location>London</location>
    </person>
    <person name="Mark" age="27">
        <location>Seattle</location>
    </person>
    <person name="Scott" age="26">
        <location>Sydney</location>
    </person>

The expanded lines are automaticaly indented. Buffer undo goes back to before awk-it invocation (both options can be changed).

During completion the folowing options are available:

After completion you can run:

Simplified AWK code differs from regular in that it:

The single mode is regular AWK code run for each default match. The previous example written in single AWK code would be:

    print "<person name=\"" $1 "\" age=\"" $2 "\">\n\
        <location>" $3 "</location>\n\
    </person>"

The raw mode is raw, or full, AWK code needed for data processing. The previous example would be:

    $0 !~ /^$/ {
        print "<person name=\"" $1 "\" age=\"" $2 "\">\n\
        <location>" $3 "</location>\n\
    </person>";
    }
    
    /^$/ { print }

AWK it! can also be invoked with every mode as starting mode, with custom separator, with contents of file inserted in interactive UI code field(in raw mode), or automatically process region with contents of file(as raw AWK).

Combining everything the following functions are available:

Also AWK it! can be customized in External → Awk it: