Skip to main content

Search and parse a field with Awk

I frequently need to do simple parsing. Often I resort to grep and cut, or a regular expression I send through Python. I rarely use something like awk.

I needed to look for a pattern in some text coming through a pipeline (“Configuration backup archive complete”), split that line up by colons, and print the second field. This is what I came up with:

| awk -F: '/Configuration backup archive complete/{print $2}'

Have a suggestion? An important correction? Let me know!

If this was helpful or enjoyable, please share it! To get new posts, subscribe to the newsletter or the RSS/Atom feed. If you have comments, questions, or feedback, please email me.