AWK
v5.1.0
AWK
v5.1.0
AWK is a domain-specific language built for scanning and processing text, line by line, splitting each record into fields automatically. CompileBytes runs GNU AWK (gawk) 5.1.0, the most feature-rich AWK implementation, which adds extensions like gensub(), true arrays, networking, and the GNU regular-expression engine on top of the classic one-true-awk behavior described by Aho, Weinberger, and Kernighan.
An AWK program is a series of pattern { action } rules: for every input line a matching pattern fires its action. Built-in variables such as NR (record number), NF (field count), and $1..$NF (fields) make tabular and log data trivial to slice. AWK shines as a glue tool in shell pipelines and for quick one-liners, but it is also a complete language with functions, arrays, and string operations.
BEGIN { print "Hello, World!" }{ print $2 }{ sum += $1 }
END { print "Total:", sum }/error/ { count++ }
END { print count, "errors" }{ print NR, $0 }{ sum += $1; n++ }
END { if (n > 0) print "Average:", sum / n }{ for (i = 1; i <= NF; i++) count[$i]++ }
END { for (w in count) print w, count[w] }function max(a, b) { return a > b ? a : b }
{ print max($1, $2) }{ printf "%-10s %5d\n", $1, $2 }Yes. CompileBytes runs your AWK programs in the browser using gawk on the server, so you can experiment with patterns, fields, and one-liners without installing anything locally.
It uses GNU AWK (gawk) 5.1.0. This means GNU extensions such as gensub(), the third argument to match(), and bit-operation functions are available alongside standard POSIX AWK.
Type your input data into the stdin box. AWK reads it record by record (by default, line by line), so each line becomes the current record $0 and is split into fields $1, $2, and so on.
Yes. GNU AWK is free software released under the GNU GPL, and running it here on CompileBytes costs nothing.
Set the FS variable, usually in a BEGIN block, e.g. BEGIN { FS = "," } for CSV input, or pass -F',' on the command line. Use OFS to control the output field separator.