3 ms·
If your awk script gets too long / unreadable you just put it in a file and use some whitespace and longer variable names. AWK scripts tend to be very readable
by unhammer 8y ago
If your awk script gets too long / unreadable you just put it in a file and use some whitespace and longer variable names.
AWK scripts tend to be very readable (much more so than e.g. sed) as long as they stick to the "stateful filters" use-case as https://news.ycombinator.com/item?id=19294195 https://news.ycombinator.com/item?id=19294195 calls it, but yes they have their limits.
If speed is a concern, you may want to try using mawk instead of GNU awk/gawk. I've had 4x speedups with mawk.
- DenseComet 8y agoBased on his timings, rust achieved a 20x speedup vs a 4x speedup if he used mawk.
- hedora 8y agoYep, and adding gnu parallel or xargs to the mix would give a # of cores speedup, which would make mawk faster than the single-threaded rust on a > 6 core machine (roughly).
- Svoka 8y agoI also find that programming with languages which has strong type system is very helpful, if you trying to make anything with logic you can't fit in one simple sentence. For example, I was parsing logs. They had entries urlencoded JSON, one document per line, each could be invalid, I had to extract 'id' field, and count number of entries with same IDs, and number of entries with same IDs and with special marker. Then take only entries with 10000+ results. You can totally write cat/grep/awk/sort/head. But then I wanted to add a field, and it was hard to edit. Rust solved my problem, and I had pleasant time writing code, not editing foot long line of untyped code.