Awk Tester
Run real awk on your own text in this tab — fields, BEGIN/END, printf and arrays, with stdout, stderr and the exit code shown.
Press ? for shortcuts · The engine is downloaded from this site once; the program and the text never leave the page.
Do it offline:$ awk '{ print $2 }' input.txt
How to use it
- Type an awk program — patterns and actions, like { print $2 } — into the program editor, or load a recipe.
- Paste the text to process into the input pane; each line becomes one record, split into fields on whitespace.
- Set a field separator (-F) for comma- or tab-separated data, and -v name=value variables if the program needs them.
- Press Run — the first run downloads the ≈1.2 MB engine once; after that every run stays on this device.
- Read stdout and stderr side by side with the exit code and timing, then copy or download the result.
Write an awk program, paste text under it, and press Run. A real awk — goawk 1.9.2, compiled to WebAssembly — executes in this tab and shows standard output, standard error and the exit code exactly as a terminal would. Fields, BEGIN and END rules, arrays and printf behave like the awk in your shell, and the engine's own error messages appear word for word. Nothing you type is uploaded.
How it works
awk reads input as records and splits each record into fields. By default a record is one line and fields are runs of non-blank characters, so $1 is the first word, $NF the last, and NF counts them. Assigning to any field — or to NF itself — rebuilds $0 with the output field separator; the idiom $1 = $1 re-joins a line after you change separators. The field separator can be a single character or a regular expression, set with -F on this page or FS inside the program.
A program is a list of pattern–action rules. BEGIN actions run before any input and END actions after the last record; every other rule runs once per record whose pattern matches. A bare pattern prints the matching record, and a bare action runs on every record. Associative arrays, getline from stdin and printf carry most one-liners: !seen[$0]++ is a complete de-duplicator in eleven characters. For pure find-and-replace over a stream of text, reach for a sed tool instead — awk's home ground is fields, records and arithmetic.
Real awk here means goawk 1.9.2 — an implementation of POSIX awk written in Go by Ben Hoyt — compiled to a WebAssembly binary that runs in a worker in this tab. The engine is downloaded from this site once, ≈1.2 MB compressed, and a 1 MiB input then runs in about 50 ms. The sandbox has no filesystem, no processes and no environment, so getline from a file, print to a file, system() and command pipes are refused up front with named banners, and every run reads the input pane as its stdin.
Examples
alpha 42.5 red
beta 7 blue
gamma 19.25 red
42.5
7
19.25{ print $2 } — whitespace splitting is the default: $2 is the second word of each line, however many blanks separate the columns.
name,qty
pens,4
mugs,2
pens
mugsNR > 1 { print $1 } with -F ',' — the comma becomes the field separator and the NR > 1 pattern skips the header record.
a 1
b 2.5
c 4
7.5{ sum += $2 } END { print sum } — variables start out zero and empty, so the sum needs no initialisation; END prints once after the last record.
one
two
one
three
two
one
two
three!seen[$0]++ — the whole program is one pattern with the default print action: the first copy of each line passes, repeats are counted and dropped.
pens 4.5
mugs 12
pens 4.50
mugs 12.00{ printf "%-6s %8.2f\n", $1, $2 } — printf with explicit widths and precision is byte-identical across awks; keep a bare %g out of portable scripts (see the gotcha below).
one 1
---------------------------------------------
^
---------------------------------------------
parse error at 2:1: expected } instead of EOF{ print $1 with no closing brace — goawk's own parse error, caret and all, at exit code 1 where the classic one-true-awk exits 2.
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
CRLF input: this engine strips the \r
Windows line endings are normalised here: goawk drops the carriage return at the end of each CRLF line, so the last field is clean. Classic BWK awk keeps that \r inside $NF — a real cross-awk difference, pinned in this page's test pack.
Uninitialised variables are both "" and 0
A never-assigned variable compares equal to the empty string and to zero at the same time, and length(u) is 0. Comparisons switch between string and numeric mode by operand type: "10" < "9" is true as strings, false as numbers.
for (k in a) order is unspecified
POSIX leaves array iteration order undefined, and this engine randomises it per run (Go map order). Collect the keys and sort them when order matters — this page's fidelity pack compares that case as a sorted set for exactly this reason.
RS is one character in this engine
POSIX defines the record separator as a single character, and goawk enforces exactly that: setting a longer RS stops the run with its own message, RS must be at most 1 char. The 2020 one-true-awk actually goes further and accepts a regular expression for RS — so here the regex form is the one that does not travel. Portable scripts keep RS to the single character.
srand() with no argument is time-seeded
srand(42) makes rand() reproducible inside this engine — 0.172461 0.130132 0.776446 on every run — but the same seed in BWK awk yields 0.033470 0.329964 0.690636: the generator behind rand() is implementation-defined. srand() with no argument seeds from the clock and repeats nowhere.
Division by zero is a runtime error
1 / 0 stops the run with goawk's own message — division by zero — and a nonzero exit code. It is not a parse error: the program starts, then fails at the offending expression.
Every cap is named, never silent
Programs cap at 8,000 characters, stdin at 1 MiB, output at 2 MiB, and a run is stopped after 5 seconds. Each limit refuses with its own banner, and cut output always carries the truncation notice.
Common errors
gensub needs gawk or a real host system — this tool runs goawk 1.9.2, a POSIX awk, in a sandbox with no processes, files or environment. Run gensub with gawk on your machine.- gensub, strftime and asort are gawk extensions, refused by name before the engine is worth downloading. Any other gawk-only call reaches goawk and comes back as its own parse error, word for word: parse error at 1:15: undefined function "gensub".
system() cannot run here — the sandbox has no processes. In this engine it returns -1 and writes "open /dev/null: Invalid argument" to stderr, so it is refused up front.- There is no process to spawn in a browser sandbox. Left to run, goawk's system() comes back with -1 and that stderr line while your command never executes — refusing up front is the honest failure.
Piping a command into getline needs a process pipe, and this sandbox has none — goawk reports "pipe: Not implemented on wasip1". Use the input pane as stdin instead.- Run in this engine, "cmd" | getline stops with error connecting to stdout pipe: pipe: Not implemented on wasip1 at exit code 1. The shape is refused before the run so the failure names itself.
Reading or writing files is not available here — the sandbox has no filesystem. Paste the data into the input pane and read stdin instead.- getline < "file" and print > "file" both need a filesystem. The input pane is this page's stdin and the stdout pane is its only output — the state file download carries program and input out.
Input is larger than the 1 MiB limit for this tool. For bigger files use the CLI: awk '{ print $2 }' input.txt- Stdin caps at 1 MiB — the band where a run still finishes in about 50 ms. Bigger jobs belong to the awk on your machine, which has no such cap.
The run took longer than 5 seconds and was stopped — narrow the program or the input and run again.- A WebAssembly call cannot be paused, so a program that never ends — while (1) with no exit — is stopped by terminating the worker after 5 seconds. The next run reloads the engine from cache.
FAQ
Which awk runs here — is it gawk?
It is goawk 1.9.2, a POSIX awk written in Go by Ben Hoyt and compiled to WebAssembly — not gawk: gawk-only builtins such as gensub and strftime are refused by name with a pointer to gawk on your machine. Against the classic one-true-awk, this page's test pack proves byte-identical output on 11 of 12 fidelity cases; the twelfth is the %g default-precision difference below.
Does my text leave this page?
No. The engine binary is fetched from this site once, ≈1.2 MB; after that the program and the text are handed to a worker inside this tab and sent nowhere. To pass work to a colleague, download the program + input as a .json state file — links carry options only, never your text.
Why does printf "%g" show more digits than awk on my machine?
Bare %g in this engine prints the shortest digits that uniquely identify the value — 12345.6789 — where C-locale awks default to six significant digits — 12345.7. That is how goawk behaves today and on its master branch, so treat it as permanent rather than a bug this page waits on. Give %g an explicit precision: %.6g matches byte for byte in both.
Why is the exit code 1 when awk in my terminal says 2?
goawk reports syntax errors with exit code 1; the one-true-awk uses 2 for the same program. The stderr text shown is goawk's own, word for word, and the exit-code note sits right where the code is displayed.
Can I read files, use ENVIRON, or run shell commands?
No — the sandbox has no filesystem, no environment and no processes, and the tool says so up front: file redirects, ENVIRON, system() and command pipes are each refused with a named banner instead of failing halfway through a run.
Is this as fast as awk in a terminal?
A 1 MiB input runs in roughly 50 ms once the engine is loaded — the same order as native goawk. The classic C awk is still faster, about 1.75× on the same workload, so iterate on programs here and run the big batch jobs in a shell.
Keyboard shortcuts
- ⌘/Ctrl + Enter
- Run the program now.
- ⌘/Ctrl + S
- Download stdout as a .txt file.
- ⌘/Ctrl + C
- Copy stdout when nothing is selected.
- ⌘/Ctrl + Shift + C
- Copy stdout even with a selection active.
- t
- Cycle the color theme.
- ? or ⌘/Ctrl + /
- Show the shortcut overlay.
- Esc
- Cancel a run, or dismiss a banner.