News for hackers. Stuff that matters.
Re:The Awk state machine parser pattern (2018) by EdwardDiego on Monday January 31, 2022 @06:10AM (#30146773)
I have to say, that's the most readable and understandable Awk program I've seen.

Does anyone know if there's a repository of similarly literate awk scripts?

Re:The Awk state machine parser pattern (2018) by OskarS on Monday January 31, 2022 @07:52AM (#30147365)
I’ve found that AWK is frequently surprisingly readable actually, as long as you understand the execution model. I think people tend to think of it (with some justification) as in the same vein as Perl, but it isn’t nearly as surface-level cryptic. The syntax is just “C-style” with dynamic typing and built in regular expressions.

I have a couple of AWK scripts to handle my personal finances (basically, consuming various bank/credit card statements and turning them to Ledger files) and it’s just the perfect language for that kind of task. My scripts look fairly similar to the examples in the blog post, they also use the same state-machine trick. With the possible exception of Perl/Raku, it’s my favourite language for that kind of thing.

Re:The Awk state machine parser pattern (2018) by patrec on Monday January 31, 2022 @06:46AM (#30146985)
Have a look at the classic "The AWK Programming Language" by the A, W, and K in awk. It's full of great examples.

https://ia803404.us.archive.org/0/items/pdfy-MgN0H1joIoDVoIC...

Re:The Awk state machine parser pattern (2018) by yiyus on Monday January 31, 2022 @06:40AM (#30146961)
There used to be very good examples in awk.info. The domain is on sale now, but you can get all the old content from archive.org and it still is very valid.
Re:The Awk state machine parser pattern (2018) by asicsp on Monday January 31, 2022 @06:22AM (#30146855)
Re:The Awk state machine parser pattern (2018) by baddate on Monday January 31, 2022 @06:34AM (#30146921)
nice!
Re:The Awk state machine parser pattern (2018) by rottc0dd on Monday January 31, 2022 @10:16AM (#30148780)
I don't know if this is idiomatic way of doing awk. It is just a port of a python script to awk.

https://github.com/berry-thawson/diff2html

This is first attempt in writing awk script. Would like to know how readable it is.

Edits : added a new line. changed some words.