Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
AWK is a text-processing language built at Bell Labs in 1977 by Alfred Aho, Peter Weinberger, and Brian Kernighan, whose initials give it its name. Its whole model is one idea: a program is a list of pattern { action } rules, and for every line of input AWK runs the action of each pattern that matches — a bare action runs on every line, and a bare pattern prints the lines that match. Fields split automatically, so $1 and $2 are columns, $0 is the whole line, NF is the field count, and NR is the current line number, which makes column extraction and quick sums almost trivial. It remains standardized by POSIX and installed on essentially every Unix system, and GNU Awk (gawk) is the actively developed implementation, adding niceties like true CSV parsing in recent releases. On XCODX your program runs against a live terminal: type input lines while it executes and watch the matching rules fire, with the exact version shown in the badge.
# Reads lines of: name score
# Prints a note per line, then a summary in the END block.
NF != 2 {
print "skip (need 2 fields):", $0
next
}
{
total[$1] += $2
count[$1] += 1
sum += $2
n += 1
}
END {
print "---- report ----"
for (name in total)
printf "%-10s total=%d avg=%.1f\n", name, total[name], total[name] / count[name]
if (n > 0)
printf "overall: %d scores, mean %.2f\n", n, sum / n
}
AWK is at its best on line-oriented text: pulling the fifth column out of a log, summing bytes per host, filtering CSV rows past a numeric threshold — jobs where a full program feels heavy and cut alone is too blunt. Choose it when the data is already in records and fields and you want a one- or two-rule transformation, which is why AWK questions still surface in DevOps and SRE interviews and in Unix-tools courses alongside grep and sed. Use this page to prototype a script against typed test lines before wiring it into a pipeline, or to finally learn what NR, NF, and associative arrays actually do. It is a poor choice for general-purpose programming — networking, rich data structures, large applications — where a language like Python or Go fits far better; AWK is a specialist, not a replacement for them.
Just type it. With no filename argument AWK reads standard input, and this terminal is interactive, so each line you type runs through your pattern-action rules immediately and matching output appears as you go. Signal end-of-input with Ctrl+D, or have the program stop on a sentinel line using an exit rule; you can also paste every line into the Stdin Box before running.
This page runs GNU Awk (gawk), the actively maintained implementation, and the exact version is shown in the badge. Everything in the POSIX standard works — BEGIN and END blocks, associative arrays, printf, split, gsub, getline, and user-defined functions — plus gawk extensions like gensub and CSV parsing. Sticking to POSIX features keeps a program identical across gawk, mawk, and BSD awk.
AWK has no package manager to install from, and the sandbox has no network, so there is nothing to fetch. gawk's own functions are all available, but system() and piping to a command through getline depend on other programs being present in this minimal environment and cannot reach the internet. Write self-contained programs that rely on AWK's built-ins.
Fields are $1, $2, $3 and so on, with $0 the whole line and NF the number of fields, so print $5 prints the fifth column. By default AWK splits on runs of whitespace; set a different separator with -F (a comma, say) or by assigning FS in a BEGIN block. NR gives the current line number when you need to filter by position.
No. Each run starts in a fresh, temporary sandbox, so anything written is discarded when the run ends and no state carries over from a previous run. That fits AWK's usual job, which is transforming a stream of input to output in a single pass. Keep everything the program needs inside the input you provide.
Yes. The editor holds a full AWK program — several pattern-action rules, BEGIN and END blocks, and user-defined functions — not just the single quoted string you would pass on a command line. This is often the clearer way to develop anything beyond a trivial rule, and you can copy the logic into a shell one-liner afterward.
main.awkplain text — no highlighter ships for this languagegetlineBEGIN {
print "Hello from AWK!"
print "Welcome to XCODX Online Compiler!"
}