Anna Shipman : JFDI

An awk command I always forget

13 October 2017

There’s a task I have to do every now and again for which awk is the best tool, but it’s infrequent enough that I always have to remind myself how. Usually by referring back to some shell scripts we wrote 5 years ago, so thought I’d post here instead.

Tell me how many different kinds there are

Given a CSV of people from different government organisations, tell me how many organisations are represented:

awk -F "," '{ print $4 }' output.csv | sort | uniq -c | wc -l

Instead of wc -l, I usually pipe to a file so I can manually edit out duplicates like MOJ/MoJ/Ministry of Justice, but that’s straightforward once I’ve done all that.

While I’m here making notes of things I forget

find . -iname *utput*

If you’d like to be notified when I publish a new post, and possibly receive very occasional announcements, sign up to my mailing list:

Email Format