Jawk 4.1.00
-
Home
- User Documentation
Jawk CLI
Getting Started
-
Download jawk-4.1.00-standalone.jar[1] from the latest release[2]
-
Make sure to have Java installed on your system (download[3])
-
Execute
jawk-4.1.00-standalone.jarjust like the “traditional” AWK:$ java -jar jawk-4.1.00-standalone.jar <command-line-arguments>
Examples
Processing of stdin
$ echo "hello world" | java -jar jawk-4.1.00-standalone.jar '{print $2 ", " $1 "!"}'
world, hello!
Execute on Windows (beware of double-double quotes!):
C:\> echo hello world | java -jar jawk-4.1.00-standalone.jar "{print $2 "", "" $1 ""!""}"
world, hello!
Classic processing of an input file
$ java -jar jawk-4.1.00-standalone.jar -F : '{print $1 "," $6}' /etc/passwd
root,/root
daemon,/usr/sbin
bin,/bin
sys,/dev
sync,/bin
games,/usr/games
man,/var/cache/man
lp,/var/spool/lpd
mail,/var/mail
Execute a script file
example.awk:
BEGIN {
totalUsed = 0
totalAvailable = 0
}
$6 !~ "wsl" && $3 ~ "[0-9]+" {
totalUsed += $3
totalAvailable += $4
}
END {
printf "Total Used: %.1f GB\n", totalUsed / 1048576
printf "Total Available: %.1f GB\n", totalAvailable / 1048576
}
$ df -kP | java -jar jawk-4.1.00-standalone.jar -f example.awk
Total Used: 559.8 GB
Total Available: 2048.0 GB
Matrix in your terminal (Linux)
$ while :;do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(printf "\U$(($RANDOM % 500))");sleep 0.05;done|java -jar jawk-4.1.00-standalone.jar '{a[$3]=0;for (x in a){o=a[x];a[x]=a[x]+1;printf "\033[%s;%sH\033[2;32m%s",o,x,$4;printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,$4;if (a[x]>=$1){a[x]=0;}}}'
Detailed Options
To view the command line argument usage summary, execute:
$ java -jar jawk-4.1.00-standalone.jar -?
Jawk supports all of the standard AWK command line parameters:
-v <name=value>- global variable assignments prior to the execution of the script.-F <fs>- input field separator assignment. This is equivalent toFS="fs"prior to its use (by getline or by input rules).-f <filename>- The script filename. If used, a script argument is not expected.
To enhance development and script execution over traditional AWK, Jawk also supports the following command-line parameter extensions:
-t- Maintain all associated arrays in key-sorted order. This is implemented by using a TreeMap instead of a HashMap as the backing store for the associated array.-K <filename>- writes the tuples to<filename>, and then halts.-l <filename>- load previously compiled tuples from the specified file.-o <filename>- Override the default output filename for extended parameters -S, -s, -z, and -Z.-S- Dump the abstract syntax tree (constructed by the front end) to a text readable file. If the -o argument is not provided, the contents will be dumped into thesyntax_tree.lstfile.-s- Dump the intermediate code (tuples) to a text readable file. If the -o argument is not provided, the contents will be dumped into the"avm.lst"file.-r- Allow IllegalFormatExceptions to be thrown when using the java.util.Formatter class for printf/sprintf. If the argument is not provided, the interpreter/compiled result catches IllegalFormatExceptions and silently returns a blank string in its place. If the argument is provided, the interpreter/compiled result will halt by throwing this runtime exception.-ext- Enables the parser/AVM to recognize extensions within scripts. Extensions allow for arbitrary Java code to be called as registered AWK functions. Please refer to the Jawk Extension Facility Description[4] page for more information.-h/-?- Displays a usage screen. The screen contains a list of command-line arguments and what each does.
If -f is not provided, a script argument is expected here.
Finally, one or more of the following parameters are consumed by Jawk and provided to the script via the ARGV/ARGC variables. The script can add/remove to this array to modify the behavior of the interpreter/compiled result.
<filename>- Uses this file as input to the script. If the filename is invalid, an error is produced on stderr, but Jawk has no direct way of notifying the script.<name=value>- Performs this assignment as a global variable assignment prior to the consumption of the next input file.
If the parameter contains an =, Jawk treats it like a variable assignment. Otherwise, it's a filename.
Note: Parameters passed into the command-line which result in non-execution of the script (i.e., -S, -s, -h, -? and -z) cause Jawk to ignore filename and name=value parameters._
Jawk parses command-line parameters via the Cli[5] class.
If an invalid command-line parameter is provided, Jawk will throw an IllegalArgumentException and terminate execution.
