Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at

hpr2613 :: Quick Awk Tip

This is a tip about awk scripts.

<< First, < Previous, , Latest >>

Hosted by Klaatu on 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:

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:


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.


Subscribe to the comments RSS feed.

Comment #1 posted on 2018-08-12 14:43:55 by Dave Morriss

Thanks for this

Hi klaatu,

Thanks for this heads-up. It *is* a confusing feature of awk, but it's the same for sed (so at least the authors are consistent). I don't think we have emphasised it enough, on reflection.

It was highlighted in show 2 of the Awk series ( and has been used many times thereafter, but hasn't been emphasised.

So, thanks again for the feedback. It's most appreciated.


Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?