Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.

hpr2613 :: Quick Awk Tip

This is a tip about awk scripts.

<< First, < Previous, Latest >>

Hosted by Klaatu on Wednesday 2018-08-08 is flagged as Clean and is released under a CC-BY-SA license.
Tags: tip,awk,shebang.

Listen in ogg, spx, or mp3 format. | Comments (1)

Part of the series: 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.

Show Transcript

Automatically generated using whisper

whisper --model tiny --language en hpr2613.wav

<< First, < Previous, Latest >>


Subscribe to the comments RSS feed.

Comment #1 posted on 2018-08-12T14:43:55Z 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.


<< First, < Previous, Latest >>

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 P in HPR stand for ?
Are you a spammer →
Who hosted this show →
What does HPR mean to you ?