Skip to content

Repository files navigation

Jawk

GitHub release (with filter) Build Reproducible GitHub top language License

Jawk is a pure Java implementation of AWK. You can run it as a CLI, embed it directly in Java applications, compile scripts to reusable tuples, evaluate AWK expressions, feed it structured input, load extensions explicitly, and enable a sandboxed runtime when you need tighter execution constraints.

Support for POSIX AWK and Gawk

Jawk fully implements POSIX AWK, and adds support for the most commonly used gawk-specific features:

  • Builtins, available by default through the built-in GNU Awk compatibility extension: asort(), asorti(), typeof(), isarray(), mkbool(), gensub(), patsplit(), strtonum(), systime(), mktime(), strftime(), bindtextdomain(), dcgettext(), dcngettext(), and PROCINFO["sorted_in"]-controlled array traversal
  • Arrays of arrays (a[i][j]), including gawk-compatible runtime typing when arrays, scalars, and subarrays are passed to functions, and typed regexp literals (@/re/)
  • Source inclusion with @include, namespaces with @namespace and ns::name, and indirect function calls such as @functionName(args)
  • BEGINFILE / ENDFILE special patterns, with the ERRNO and ARGIND special variables, so a script can hook into the command-line file processing loop and skip unreadable files without a fatal error
  • The nextfile statement
  • The IGNORECASE, SYMTAB, and FUNCTAB special variables
  • The /dev/stdout, /dev/stderr, and /dev/stdin special filenames (and their /dev/fd/N spellings) in redirections and getline, routed to the standard streams of the process instead of files of those names, and /dev/null mapped to the platform's null device on Windows too, as gawk's Windows port does

The gawk-specific @ syntax and arrays-of-arrays syntax are rejected in --posix mode.

See the compatibility page for detailed behavior notes and live compatibility reports against the POSIX, One True Awk, and gawk test suites.

Installation

Install the jawk command with one line; the launcher finds a Java runtime (Java 8 or later) automatically:

curl -fsSL https://jawk.io/get | sh

On Windows (PowerShell):

irm https://jawk.io/get.ps1 | iex

See the installation page for details, Maven/Gradle coordinates, and the standalone jar.

CLI Example

echo "hello world" | jawk '{ print $2 ", " $1 "!" }'

The CLI follows the POSIX argument conventions: -- marks the end of options, and the - operand designates standard input as an input file (with FILENAME set to -). As in gawk, once the program text has been supplied (with -f or -L), an unknown option ends option processing and is passed on to the AWK script through ARGV, which makes #! interpreter scripts work. See the CLI documentation for details.

Java Example

Awk awk = new Awk();
String result = awk.script("{ print toupper($0) }").input("hello world").execute();

When writing custom extensions, annotate associative array parameters with @JawkAssocArray and declare them as Map values rather than concrete map implementations.

Java variables passed to embedded Jawk scripts may include Map and List values, including nested JSON-like object trees. Lists are materialized as AWK arrays with zero-based numeric indexes.

Documentation

Contributing

See CONTRIBUTING.md.

About

Java AWK interpreter

Topics

Resources

Contributing

Stars

9 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages