Explain awk code
Paste awk, one-liners included, and Vibe explains which lines each pattern picks, which column each $ number reads and what an array is adding up.
Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Anthropic to write the explanation. Don't paste keys or passwords. Common key formats are refused.
Vibe24 lines selected
Press Explain it for the sample, or paste your own code first.
What this awk sample shows
- fields
FS = ","splits every line at its commas, so$2is the region and$4is the amount. awk turns$4into a number when it adds it:12.50adds 12.5, and text that doesn't start with a number adds 0.- patterns and actions
- Each
pattern { action }runs on every line its pattern matches, in order from the top.NR == 1 { next }matches the first line, andnextmoves straight on to the line after, so the header never reaches the totals.$4 == ""catches a sale with no amount, and the last block has no pattern, so it runs on every line still left. - associative arrays
total[$2] += $4uses the region as the key. The first time a region turns up its entry is empty, which counts as 0, so nothing has to be set up first.rows[$2]++counts each region's sales the same way.- BEGIN and END
BEGINruns before the first line is read, which is whyFSis set there, andENDruns after the last one.for (region in total)visits the keys in no set order, so each line goes throughsort -k2 -rn, which sorts on the second column as a number, largest first.
Good to know
- Run on six sales with one missing amount, the script prints
west32.50 from 2 sales,east28.00 from 2 andnorth12.50 from 1, then1 rows had no amount. close("sort -k2 -rn")waits forsortto finish. Without it,1 rows had no amountcame out above the totals in this run, becausesortcan't print anything until its input is closed, and awk only closes it on exit.- Given two files,
NRkeeps counting across both, so only the first header is skipped: the second file's header adds a region calledregionwith 0.00.FNR == 1starts again for each file and skips both headers. - The sample was run with the awk that comes with macOS,
awk version 20200816, and uses only standard awk. Sorting inside awk withasortorPROCINFO["sorted_in"]is gawk-only, which is why the sample hands its lines tosort.
Watch out: awk splits at every comma, even one inside quotes. A product written "poster, large" becomes two fields, so $4 is the text large" with a space in front, which counts as 0: that sale's 30 is lost and west shows 12.50 from 2 sales, with no error. gawk 5.3 and later have a --csv option that reads quoted fields, while this macOS awk prints unknown option --csv ignored.
Explain awk code beside your editor
Unvibe is a free app for Mac and Windows. In the app there is no pasting: select code in any app and press Control+U (Ctrl+Alt+U on Windows).
Install on Mac
curl -fsSL https://unvibe.site/install.sh | bashPaste into Terminal. Unvibe isn't notarized by Apple yet, so this is the smooth path.
Or download the .dmg · Intel Mac build · SHA-256 checksums
Opening the .dmg the first time
- Open the .dmg and drag Unvibe to Applications.
- Open it once; macOS says it can't verify it. Click Done.

Real screen, macOS 15 - System Settings › Privacy & Security › Open Anyway. Confirm, then enter your Mac password. The button shows for about an hour after you try to open Unvibe.

Real screen, macOS 15
The Terminal line checks the download against the published SHA-256 and Unvibe's self-signed signature before it installs anything. More help with the first open