hpr2613 :: Quick Awk Tip
This is a tip about awk scripts.
Hosted by Klaatu on Wednesday, 2018-08-08 is flagged as Clean and is released under a CC-BY-SA license.
tip, awk, shebang.
1.
The show is available on the Internet Archive at: https://archive.org/details/hpr2613
Listen in ogg,
spx,
or mp3 format. Play now:
Duration: 00:07:39
Learning Awk.
Episodes about using Awk, the text manipulation language. It comes in various forms called awk, nawk, mawk and gawk, but the standard version on Linux is GNU Awk (gawk). It's a programming language optimised for the manipulation of delimited text.
This is obvious, but it tripped me up a few times after listening to the excellent Awk series by Dave and B-yeezi, so I though I'd share it here to save others the trouble.
When moving from simple awk commands to proper awk scripts, you put a shebang line at the top of your script. It's pretty common to many of us, because we do it for Python and Bash all the time.
But if you just put:
#!/usr/bin/awk
Then your awk script won't work the way you expect.
You must provide the -f
flag:
#!/usr/bin/awk -f
Now you can pipe things to your awk script as expected.