Jawk 3.3.05
-
Home
- User Documentation
Jawk CLI
Getting Started
-
Download jawk-3.3.05-standalone.jar[1] from the latest release[2]
-
Make sure to have Java installed on your system (download[3])
-
Execute
jawk-3.3.05-standalone.jar
just like the “traditional” AWK:$ java -jar jawk-3.3.05-standalone.jar <command-line-arguments>
Examples
Processing of stdin
$ echo "hello world" | java -jar jawk-3.3.05-standalone.jar '{print $2 ", " $1 "!"}'
world, hello!
Execute on Windows (beware of double-double quotes!):
C:\> echo hello world | java -jar jawk-3.3.05-standalone.jar "{print $2 "", "" $1 ""!""}"
world, hello!
Classic processing of an input file
$ java -jar jawk-3.3.05-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-3.3.05-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-3.3.05-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-3.3.05-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.-c
- writes the tuples (generated by the Intermediate Subsystem) to a file, and then halts. If the -o parameter is provided, use its optarg as the filename. Otherwise, write to"a.ai"
. This file can be used as an argument to -f to avoid the front end and intermediate steps for a particular script. It also provides a measure of script obfuscation.-o <filename>
- Override the default output filename for extended parameters -c, -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.lst
file.-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.-x
- Enable**_sleep**
,**_dump**
and**exec**
keywords._sleep
causes the execution thread to sleep for a specified number of seconds (or one second if no argument is provided), and_dump
dumps the global variables (names and values) to stdout. If associative array arguments are provided,_dump
dumps the contents of each associative array to stdout. Andexec
dynamically parses and executes complete AWK scripts, however in a separate vairable environment.-y
- Enable**_INTEGER**
,**_DOUBLE**
and**_STRING**
typecast keywords. These are particularly useful in [s]printf functions/statements to force parameters to convert to particular types.-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 employs the org.metricshub.jawk.util.AwkParameters[5] for command-line parameter management.
If an invalid command-line parameter is provided, Jawk will throw an IllegalArgumentException and terminate execution.