6 ms·
The only really horrid thing about awk is the way you declare local variables in a function ... by just adding more parameters (and letting them be default-init
by veltas 5y ago
The only really horrid thing about awk is the way you declare local variables in a function ... by just adding more parameters (and letting them be default-initialised on calls). Otherwise it can act like a relatively conventional scripting language, aware of associative arrays (ahead of its time).
- OskarS 5y agoI have really warm feelings about AWK, actually! It’s such a simple language that you can learn pretty much all of it in an afternoon, but it is still expressive enough to be really useful as a text processing language. I have an AWK script that turns my CSV bank statements into Ledger transactions, and AWK is just perfect for that kind of thing.
- kmarc 5y agoLOL that's what I do too. A bit of pdf2txt, awk and some shell scripting, and budgeting becomes very easy...
- veltas 5y agoDidn't mean to sound negative about it, I love awk too. It is definitely small enough to learn in a day (or two), and it fills a niche people don't realise they have.
- hkt 5y agoCan you share? I've been thinking of doing the same and would love to see some prior art.
- asdff 5y agobe wary that the initial parsing is probably going to be bespoke for your bank account csv export format. my own bank doesn't even share consistency in these exported csvs between the checking, savings, and the credit card I have with them.
- jrochkind1 5y agoAwk more or less introduced associative arrays to modern programming.
- IncRnd 5y agoSNOBOL4 was earlier than AWK with associative arrays by a little under ten years. However, from the standpoint of manipulating strings with regular expressions, AWK introduced the concept as far as I know.
- gompertz 5y agoString pattern matching in Snobol4 was still stronger than regex for a very long time, possibly still today. A language very ahead of its time.
- abecedarius 5y agoYep, I recommend Gimpel's old book Algorithms in SNOBOL4 for fun examples (from the days when such a title did not mean an undergrad data-structures-and-algorithms curriculum).
- gompertz 5y agoAgreed it is an excellent book. Even the Catspaw Spitbol manual is well written. Along with the Green Book. An often forgotten period of computing!
- jrochkind1 5y agoI did say "more or less" and "modern". Who's heard of SNOBOL4 now? :) My guess is that every other language that got AA's got them by way of influence from awk (or something else that got them from awk); awk itself may have gotten them from SNOBOL4 though. But ok, we can at least say that awk is the oldest programming language to have associative arrays that's still in widespread use. (Yes, I'm hoping that someone will argue for SNOBOL4's current widespread use. :) ) > However, from the standpoint of manipulating strings with regular expressions, AWK introduced the concept as far as I know. Two can play at this game! `awk` is really a successor of `sed`, which is all about manipulating strings with regular expressions. sed maybe isn't turing complete though (but someone's gonna prove me wrong here too) or at any rate not convenient to use in as general a way as awk.
- KMag 5y agoBack in Google New York, sometime after 2006, but prior to my team changing floors after the YouTube acquisition, my team sat about 2 cubicles over from Peter Weinberger, and a bit further from Brian Kernighan's office. My manager, John Sarapata was standing up and complaining how much he hated awk, and I ducked a bit and said "You know AWK stands for Aho, Kernighan (motion toward Brian's office), and Weinberger (motion toward Peter's desk), right?" They're both very nice people, so I don't think they would have been too offended, but it just felt odd to be boldly talking behind the backs of such well-recognized luminaries. Last I checked, John was very senior in Google NYC, so I guess he's a bit more careful to get full context before complaining loudly. Good times.
- notsureaboutpg 5y agoJust makes me think of olden days intellectuals and the tiffs they would get into when each other's ideas were disrespected compared to this.
- pantsforbirds 5y ago1. This is an incredible story haha. 2. I constantly talk about how much I hate python or other languages that I actually like. Sometimes the things you complain about most are the things you need most too
- bananabreakfast 5y ago"There are two types of programming languages: those everyone complains about, and those nobody uses."
- vram22 5y ago- Bjarne Stroustrup. I agree with him. His book "The Design and Evolution of C++" was a fascinating read. His site has an overview of it.
- chubot 5y agoA big problem with Awk is that it lacks garbage collection (including ref counting), and that puts major limitations on the language. You can't return an associative array from a function: $ awk 'function f() { a[1]=2; return a } BEGIN { f() }' </dev/null awk: cmd. line:1: fatal: attempt to use array `a' in a scalar context You also can't have nested associative arrays, i.e. recursive or cyclic data structures are not allowed. As far as I can tell, this is because a stack frame owns everything allocated within it, and when a function returns the whole stack frame is cleaned up unconditionally. You can pass arrays down but not up. It's very naive memory management (by modern standards; it's probably better than BASIC). So I'd say it's clearly not expressive enough for general purpose programming. There are Lisps in awk but they do weird tricks with text as far as I remember.
- bitwize 5y agoMany BASICs had GC to clean up strings -- even on rinky-dink 8-bit micros.
- amelius 5y agoThank you. This comment alone is enough reason to never touch Awk if I can help it.
- ghshephard 5y agoYou definitely want to work with it if you can. I live much of my life in python, but there hasn't never been a week, and usually not a day, in the last 10+ years where I don't write a quick awk snippet to do something useful to data. The advantage of awk over python is that it almost always takes < 60 seconds from the point at which you say, "I want to summarize, review, filters, report" on some columnar data to the point at which you have output in front of you. I"m fast with python doing that - but it's usually a 3-4 minute set of steps. The only exception being json, which awk is clumsy with. (jq is my goto tool for the simple queries, python for anything that requires more than a minute of thought.) Also - it's almost always the case that I'm using awk in conjunction with a bunch of other tools, cut/sed/uniq/grep to get what I want.
- 5y ago