News for hackers. Stuff that matters.
Re:The Awk Programming Language (1988) [pdf] by coliveira on Thursday May 24, 2018 @12:16AM (#17141045)
I consider awk to be the most useful and underused language in the UNIX ecosystem. I use it daily to analyze, transform, and assemble data, and it always blows my mind that so few people really know how to use it at a decent level. This is an excellent book to give a real idea of what awk is capable of.
Re:The Awk Programming Language (1988) [pdf] by ajross on Thursday May 24, 2018 @12:23AM (#17141077)
> it always blows my mind that so few people really know how to use it at a decent level

Not nearly as surprising as it is to me that now that most developers have forgotten perl, they're turning to awk as an inspiring example of a bygone era.

Seriously: perl basically replaced awk in the mid-90's. It absorbed all the great lessons and added two or three dozen innovations. But it had scary syntax, so everyone used python (which did not replace awk very effectively) and forgot perl. So now we're back at awk. And the scary syntax is all in the Rust world.

Re:The Awk Programming Language (1988) [pdf] by TurboHaskal on Thursday May 24, 2018 @05:58AM (#17142534)
Perl deprecates awk & sed [0]. Whereas Python is a bad substitute for those, and because of that, we're back on Awk. I have the feeling that Python simply succeeded as it seems to be a language designed for people that do not enjoy programming, which sadly seem to be the majority in our industry.

The Perl hate is so prevalent in most companies, that you can get into serious issues should you even write a one-liner in it. So here I am, reluctantly using awk/sed and asking too much of Bash/Python.

[0] https://www.manning.com/books/minimal-perl

Re:The Awk Programming Language (1988) [pdf] by mauvehaus on Thursday May 24, 2018 @12:31PM (#17145661)
Ooof. I have to respectfully disagree that perl deprecates awk. If I'm writing awk, it's usually because what I want to do is precisely what awk does by default: read a line, match it against a condition, and perform some action.

I could do all that in perl, but it's more stuff I'd need to dig up every time I wanted to do something awk-like. People who code perl regularly already have it, for sure. It's a barrier for those of us who don't, and one that awk doesn't have.

Awk isn't perfect, for sure, but I've transitioned from writing simple text processing in perl to doing it in awk because awk provides the basic framework that I'd end up doing ad-hoc and non-idiomatically in perl every time.

Again, all this with that caveat that I'm not a perl programmer. I used it for a couple of semesters in college, which was enough to be dangerous, but not truly proficient.

Re:The Awk Programming Language (1988) [pdf] by freeone3000 on Thursday May 24, 2018 @02:20PM (#17146802)
`perl -n` wraps code in an awk-alike start and finish stanza.

`perl -p` wraps code in a sed-alike start and finish stanza.

Re:The Awk Programming Language (1988) [pdf] by Koshkin on Thursday May 24, 2018 @08:39PM (#17149742)
So, basically, if I understand, Perl has both awk and sed built in.
Re:The Awk Programming Language (1988) [pdf] by vram22 on Friday May 25, 2018 @07:40PM (#17159088)
Yes, as per what I read long ago, Larry Wall created Perl as a sort of superset of parts of awk, sed, shell and C (maybe not shell).
Re:The Awk Programming Language (1988) [pdf] by harry8 on Tuesday May 29, 2018 @01:55AM (#17176799)
absolutely shell. Perl acts as glue between multiple processes very nicely. $foo = `foo_command`; is great. Opening named pipes. Python is more awkward because it's less like shell.
Re:The Awk Programming Language (1988) [pdf] by vram22 on Tuesday May 29, 2018 @02:31PM (#17181802)
Thanks, didn't know that about Perl.
Re:The Awk Programming Language (1988) [pdf] by Annatar on Thursday May 24, 2018 @06:39AM (#17142711)
If one writes a Perl one-liner where AWK will do, that’s avarice.

I used to maintain and debug a relatively large and an extremely complex build engine in Perl for a living for several years, and there was no construct in there that could not have been easily written in AWK.

Re:The Awk Programming Language (1988) [pdf] by blowski on Thursday May 24, 2018 @06:05AM (#17142581)
> a language designed for people that do not enjoy programming, which sadly seem to be the majority in our industry

Could you expand a bit on that comment?

Re:The Awk Programming Language (1988) [pdf] by mjburgess on Thursday May 24, 2018 @06:39AM (#17142710)
If I can add my interpretation of his comment:

Consider which language is sold to people-off-the-street as "How to Program!" it's python. Most of these people do not enjoy the cognitive effort, detailed typing and symbolic work, algorithmic thinking, architectural thinking, linguistic thinking that is "programming". At best, the enjoy the end result, but not the process.

Python taught in this way at least, fools people into thinking that programming is about something far simpler and more toylike than it is. Many "hard" disciplines do this: sell children and lay people on toy experiments that momentarily captive but have no relationship to what a practitioner of that discipline does.

The older system of recruitment would be to polarized hard, ie., to throw people in at the deep-end to scare off all the people who would waste time/resources training. Who remained really wanted to do that thing (eg. physics, programming, ...).

Today we're doing something perhaps vaguely immoral: selling people on a career that has no relationship to the sales pitch.

Re:The Awk Programming Language (1988) [pdf] by blowski on Thursday May 24, 2018 @06:59AM (#17142812)
To me, that sounds like gatekeeping - as in "it's only programming when it's insanely difficult".

Somebody playing football in a Sunday pub league is still playing football, and still loves playing football, even if they're not at the same standard of Lionel Messi.

For me at least, I feel the same about programming. I love understanding somebody's problem, and building a solution for them that solves that problem. I normally use PHP (and sometimes Python or Ruby or JavaScript) because they make it easier for me to focus on the problem, rather than language details. I can't always solve the problem because it's too difficult, and perhaps some of my solutions are not 'optimal'. But I feel hurt by the idea that because I don't have a strong understanding of how Python works at a really deep level, I'm not a real programmer.

I also think that's a great way to piss people off who are just getting into the industry, and may one day become great programmers - even Linus Torvalds was a junior once. I'd encourage them to keep going, keep learning, and keep helping people solve their problems (and getting paid good money for doing that).

Re:The Awk Programming Language (1988) [pdf] by mjburgess on Thursday May 24, 2018 @07:19AM (#17142910)
Its only gate-keeping if people want to be past the gate. I'm not talking about deterring people who are interested.

The vast majority of people do not want to be programmers and would not enjoy programming. Delaying the moment the actually have to do something difficult with a programming language is not especially heathly.

How would you feel about a career in football sold to you on the basis of table pong? Keep playing the pong, and then one day, you're face is in the dirt and you drop out.

The self-esteem hack psychology of the 60s-90s equivocated encouraging people with lying to them, as-if the only way we can get programmers is by lying about what programming is about. This isnt encouraging anyone, it's lying to them.

Re:The Awk Programming Language (1988) [pdf] by exelius on Thursday May 24, 2018 @08:30AM (#17143277)
I think you’re confusing “programmer” with “10x programmer”. Plenty of people are capable of implementing business logic in code. Very few are capable of designing that logic — they’re the 10x programmers who know all about data structures, algorithms, etc.

You can’t run a business expecting every employee to be a rockstar. It just doesn’t scale. So you skill it down and put the high-skill people where they can have the most impact.

Re:The Awk Programming Language (1988) [pdf] by blowski on Thursday May 24, 2018 @10:48AM (#17144494)
It sounds like we have a different definition of programming. For me, programming is producing code that gets executed by another piece of hardware or software.

The complexity of the code is not part of the definition. Nor is your understanding of the hardware/software involved.

Re:The Awk Programming Language (1988) [pdf] by mjburgess on Thursday May 24, 2018 @11:21AM (#17144856)
Enjoying programming is enjoying programming. The way it is sold, sometimes, is not as programming.

Unless you've experienced this sales pitch you're not going to connect with the point i'm making.

Re:The Awk Programming Language (1988) [pdf] by kchr on Friday May 25, 2018 @11:31AM (#17154650)
Care to give an example pitch from the real world?
Re:The Awk Programming Language (1988) [pdf] by singingfish on Friday May 25, 2018 @08:41AM (#17153040)
Perl isn’t difficult in the same way that the English lnguage isn’t difficult. Easy to get started with, takes a long time to master. Fortunately for us die hard perl types it’s quite capable of cleanly solving all normal dynamic language problems, and some seriously abnormal ones. And because of the insanely good backcompat in perl we’ll see the pendulum swing back to perl 5 some time in the next decade.
Re:The Awk Programming Language (1988) [pdf] by kamaal on Thursday May 24, 2018 @09:22AM (#17143699)
>>To me, that sounds like gatekeeping - as in "it's only programming when it's insanely difficult".

The whole point of programming is power and flexibility. Else there would be no need to move beyond logic gates.

The problem is tools sold for newbies tend to take away too much power to make it easy for people to start, but then keep them, right there, all life.

Re:The Awk Programming Language (1988) [pdf] by ams6110 on Thursday May 24, 2018 @08:53AM (#17143445)
When I did my comp sci undergrad degree, languages per-se was not part of what was taught in the classroom. Whatever language that class was using, be it assembler, scheme, C or some other higher level language, it was up to the student to figure out the syntax, how to run the compiler, etc. You got some help and basic examples in the discussion sessions but it was not part of the lectures. And there was no web, no stack overflow, no google at the time. You had a book about the language, some local newsgroups (and the larger USENET) and that was it.

If you didn't enjoy reading, puzzling, and banging your head against the wall you would wash out after a couple of classes.

Re:The Awk Programming Language (1988) [pdf] by code_duck on Thursday May 24, 2018 @07:17AM (#17142900)
What language do you think beginners should be learning that would not keep them from what you say is ‘cognitive effort, detailed typing and symbolic work, algorithmic thinking, architectural thinking, linguistic thinking’. Perl? And why is Python incompatible with those things?

Like many of us, I started programming with BASIC, not C or assembly, but I turned out fine. I don’t think people need to or necessarily can absorb all the high level details straight off. To me python seems well organized enough that it makes a great language for beginners.

Re:The Awk Programming Language (1988) [pdf] by mjburgess on Thursday May 24, 2018 @07:26AM (#17142947)
Python is fine.

Python is perhaps my favorite language, and I use a dozen fairly regularly.

My point was about how python sometimes gets used, and how its design is especially facilitating to that use.

Re:The Awk Programming Language (1988) [pdf] by code_duck on Thursday May 24, 2018 @07:31AM (#17142974)
As far as the second part of your comment, I think if you make topics like this impenetrably difficult and complex at first, it will not only filter out the non-dedicated, but also those who don’t yet know that they would like to be dedicated to it.
Re:The Awk Programming Language (1988) [pdf] by singingfish on Friday May 25, 2018 @08:11AM (#17152777)
Aka python helps you think more like the computer does. Perl helps the computer think more like you.
Re:The Awk Programming Language (1988) [pdf] by tzahola on Thursday May 24, 2018 @02:11PM (#17146700)
Python is the rubber sheet analogy of programming.
Re:The Awk Programming Language (1988) [pdf] by kqr on Thursday May 24, 2018 @07:52AM (#17143079)
Note that it sounds like a snide remark but it doesn't have to be. One could interpret it as, "Do you want to simply get things done, and not bicker endlessly about microoptimizations or where the braces go? Python is for people who simply want to complete their tasks and then go home and spend their time doing more stuff they think is fun."

It's not necessarily a bad thing to be productive, instead of inventing new problems for yourself to keep having programming things to do.

(Note that none of this necessarily reflects my personal opinion; it is just an alternative way to read the grandparent.)

Re:The Awk Programming Language (1988) [pdf] by snarfy on Thursday May 24, 2018 @06:41AM (#17142720)
The cargo cult continues.

It's disgusting how much we all rely on intuition and gut feelings when evaluating large swathes of technology. The internet hates perl so people criticize it without even using it. People will use what everybody else is using without actually trying out the options. There's too much information and so we must go with what others have said, and it all becomes hearsay. Keeping up is more like wizardry than engineering. Go with what the crowd says because I can't possibly install all of those libraries, play with the examples, and give my own evaluation. Hey look a new js framework just came out...

Re:The Awk Programming Language (1988) [pdf] by adamc on Thursday May 24, 2018 @01:06PM (#17146059)
I used it quite a bit, and wrote some applications in it that are still in use a decade later. The "write-only" aspect of Perl is real -- it enables many styles and idioms, and as a result, tends to requires reading knowledge of all of them. It also has some unusual design decisions (list vs. scalar context) and some hacks ("bless") that do not contribute to readability, especially for people who do not get to use Perl all day long. Python is a lot more readable, and does most of the same stuff.

What Perl did that was amazing was bring regular expressions "to the masses", and Perl-compatible regular expressions (pcre) are still the defacto standard that most subsequent libraries have used (more or less).

"The internet" is an abstraction and doesn't hate (or love) anything. That itself is the kind of gross generalization you are criticizing. And one can criticize a language and still have respect for it.

Re:The Awk Programming Language (1988) [pdf] by busterarm on Thursday May 24, 2018 @08:50AM (#17143422)
Let's be honest -- people only use what everyone else is using because it lowers the bar to getting hired to 90+% of programming jobs.

I can count the number of tool-agnostic development teams that I've met on one hand. Many more have claimed they are when they are not.

If you aren't aiming for the top 10% of jobs (vague quality metric that you can interpret as you wish), then you want to have above-average knowledge of _just_ Python, Go, React, Docker and Kubernetes.

The situation only changes when high profile current/ex-Googlers (or similar) start talking about a language/tool a lot. Then the mass hops on board that train too.

Re:The Awk Programming Language (1988) [pdf] by adamc on Thursday May 24, 2018 @01:11PM (#17146100)
I agree with the thrust of your comment but not the specifics. There are still a ton of Java and JavaScript (not necessarily React) jobs out there in the "bottom 90%".

And I don't think "high-profile" people talking has much effect. Paul Graham talked up lisp for a while, and I was certainly interested (I like lisps), but... there are still precious few jobs that use Lisp. Most people learn technologies that they either need currently or are in use in jobs they know of and might conceivably get.

Re:The Awk Programming Language (1988) [pdf] by busterarm on Thursday May 24, 2018 @03:46PM (#17147607)
Even at shops just hiring for Java or JavaScript, I don't think knowing them is a career advantage. They don't make you more hirable than you would be otherwise. That's really the only reason I left those out.

Paul Graham, while a thought-leader of sorts, isn't generally thought of as someone working at either the edge of tech or in large-scale systems. That's why nobody wants to chase the tech he's using vs what Google/Facebook/etc are.

Re:The Awk Programming Language (1988) [pdf] by carlmr on Thursday May 24, 2018 @06:28AM (#17142662)
>And the scary syntax is all in the Rust world.

There's something like necessary complexity you can't easily abstract away. I find Rust does a fine job at cleaning up syntax. I'm not a fan of snake_case. Other than that I can't think of anything that's more difficult than the underlying concept in Rust. And it's still close to C (braces and functions) and ML syntax (type after colon and variable name, let bindings) in many ways.

Especially compared with a similarly complex language like C++. Now that is scary syntax, if you're not used to it from 20 years of using C++ and developing Stockholm Syndrome.

Re:The Awk Programming Language (1988) [pdf] by ajross on Thursday May 24, 2018 @10:15AM (#17144138)
Oh, don't be silly. Exactly the same point you're making about rust can be made about both C++ and perl by expert practitioners. Syntactic complexity is linear with expressive power, that's why it's complex to begin with. You just "like" rust, so you view it as a good tradeoff there and not in other languages that you "dislike".

My point above was that this decision is basically one of fashion and not technology. And the proof is how the general consensus about awk has evolved over 20 years as perl has declined.

Re:The Awk Programming Language (1988) [pdf] by derefr on Sunday May 27, 2018 @06:44PM (#17169521)
Are you confusing syntax with grammar? Rust has a large grammar—many reserved words, many compile-time macros, etc.—but not too much in the way of syntax (e.g. novel punctuational operators; novel kinds of literals; etc.)

C++ and Perl, meanwhile, both have tons and tons of syntax, such that they're 1. harder to grasp for people who haven't seen them before, and 2. harder to learn (especially by attempting to Google language features "by name.")

If there was a spectrum with Lisp [or Forth] on one end and APL on the other, Rust might be somewhere right-of-center... but it'd still be pretty far left of C++ and Perl.

Also, given the languages that occupy the ends of said spectrum, I think it should be clear that your position on said spectrum has no correspondence with "expressive power" :)

Re:The Awk Programming Language (1988) [pdf] by carlmr on Monday May 28, 2018 @02:46AM (#17170926)
You said it better than I could :)
Re:The Awk Programming Language (1988) [pdf] by kazinator on Sunday May 27, 2018 @07:45PM (#17169803)
Awk has evolved? GNU Awk has---somewhat. It has a clumsy facility in the place of a proper FFI called the "extension API" for binding to C libraries. You need to compile C code to use it, and the API has been a moving target. It has a way to work with XML. It has an "in place" editing mode, and other things like bignum integer support via GMP (requiring the -M option to be used). Plus various minor extensions to POSIX, like full regex support in RS (record separator), a way to tokenize fields positively rather than delimit by matching their separators, a way to extract fixed-width fields, an @include mechanism, a way to indirect on functions and such. None of it adds up to very much.
Re:The Awk Programming Language (1988) [pdf] by carlmr on Friday May 25, 2018 @06:32AM (#17152164)
I like C++, but it's not the language that you would design if you hadn't accumulated so much cruft over the years. Rust didn't have to support C compatibility and compatibility with earlier C++ standards. So Rust could be designed properly for modern use cases.

There's necessary complexity to express certain concepts, but C++ has accumulated a lot of unnecessary complexity over the years.

Rust, in terms of GC-less languages with mostly zero-cost abstractions is the simplest language that I've seen. And having a GCless language with memory safety is not just fashion. It's pretty much the greatest single advancement in language design since the GC itself.

Re:The Awk Programming Language (1988) [pdf] by quiq on Thursday May 24, 2018 @08:29PM (#17149704)
> Syntactic complexity is linear with expressive power

Have you taken a serious look at a lisp? You might be pleasently surprised. Everything that can be said about lisp has probably already been said, but I'd argue that sexprs have a much higher expressive/complexity ratio than say the C++ grammar.

Somewhat relative xkcd[1]

[1] https://www.explainxkcd.com/wiki/index.php/224:_Lisp

Re:The Awk Programming Language (1988) [pdf] by wenc on Thursday May 24, 2018 @01:51AM (#17141414)
Second this. Perl replaced both awk and sed. Data scientists marvel at awk/sed but Perl is somehow forgotten. Perl May not be as suited to writing complex programs, but for text processing tasks, it is much more elegant than awk or sed.

Perl -pie is a very powerful idiom.

I would rather use a subset of Perl than awk.

Re:The Awk Programming Language (1988) [pdf] by tannhaeuser on Thursday May 24, 2018 @02:51AM (#17141614)
That's the first time I'm hearing Perl being praised for its elegance of all things. Elegance is certainly in the eye of the beholder, but by default is understood in the context of programming languages as "containing only a minimal amount of syntax constructs". By that measure, Perl is spectacularly/absurdly bad with its "sigills" and "there's more than one way" idioms. In fact, I find Perl one of the ugliest languages of all time.

Edit: a-ok, probably elegance is meant in the same sense that C is elegant by cramming everything in a single statement using pre-/post-increment operators and assignments-as-expressions

Re:The Awk Programming Language (1988) [pdf] by kqr on Thursday May 24, 2018 @03:19AM (#17141760)
One has to recall that there were some forces that wanted Perl to become a standard shell rather than a programming language. A shell is usually more limited in features, but it is frequently very forgiving, provides many shortcuts, and there are often multiple ways of doing things.

However, I've never believed it to be possible to have a language both as a shell language and a proper programming language for large-scale projects. I believe the two usecases are fundamentally antithetical, but I'd be happy to be proven wrong.

Re:The Awk Programming Language (1988) [pdf] by oblio on Thursday May 24, 2018 @04:42AM (#17142207)
> However, I've never believed it to be possible to have a language both as a shell language and a proper programming language for large-scale projects. I believe the two usecases are fundamentally antithetical, but I'd be happy to be proven wrong.

I'd say Powershell proves you right. Powershell has a great design, it has optional typing and access to a cornucopia of libraries via .NET.

Even so, they had to make some compromises because of the shell parts (functions return output, for example) which makes is quite finicky as a "proper" programming language.

On the shell side, the very nice nomenclature which makes it very readable and discoverable makes is annoying sometimes to use as a shell. That and the somewhat unwieldy launch of non-Powershell commands.

Someone who attempts to bridge the two has a ton of work to do, both in the research and in the implementation department. I guess Oil Shell (https://www.oilshell.org/) is the most realistic approach we have today. And it's probably still 1-2 years away from release and many more years from mass adoption (if that ever happens).

Re:The Awk Programming Language (1988) [pdf] by asicsp on Thursday May 24, 2018 @02:38AM (#17141571)
yeah.. I like the `s///` syntax in sed/perl than the `sub/gsub` syntax.. plus the regex is lacking in awk.. no backreference(gawk provides, but only in replacement section).. and perl has non-greedy, lookarounds, code in replacement section, etc

other nice features I'd like in awk is `tr` and `join`

Re:The Awk Programming Language (1988) [pdf] by ams6110 on Thursday May 24, 2018 @09:04AM (#17143541)
Why add 'tr' and 'join' to awk when they exist on their own?

That's part of why people avoid perl. It's very capable, but that wide scope is counter to the unix philosophy that prefers simple, focused utilities that can be combined in pipelines.

Re:The Awk Programming Language (1988) [pdf] by asicsp on Thursday May 24, 2018 @09:20AM (#17143686)
looks like I didn't word it properly...

you could ask why have sub/gsub when there is sed... that's because you need that for specific field or string in addition to other processing.. similarly, having tr for specific string/field is useful..

I meant join as in perl's join - to construct a string out of array values with specified separator

Some examples:

* https://stackoverflow.com/questions/48920626/sort-rows-in-cs...

* https://stackoverflow.com/questions/45571828/execute-bash-co...

* https://stackoverflow.com/questions/48925359/sorting-groups-...

Re:The Awk Programming Language (1988) [pdf] by nameiscubanpete on Sunday May 27, 2018 @08:30AM (#17166643)
I think perls niche is sort of it's downfall. For example, I used to work at a company with 70% C, 25% shell script, and 5% perl. Any time I ran into a perl script I had to switch my brain into Perl mode, with the understanding that what I was working on would be just as good or better in C or shell. I had nothing against Perl as a language, but always enjoyed exorcising a perl script from the codebase.
Re:The Awk Programming Language (1988) [pdf] by jclulow on Thursday May 24, 2018 @02:39AM (#17141574)
Ah, but which subset?
Re:The Awk Programming Language (1988) [pdf] by kqr on Thursday May 24, 2018 @12:25AM (#17141085)
What I like about AWK is that it is described by a few pages of the POSIX standard. If Perl was that ubiquitous and simple, I would prefer it over AWK.
Re:The Awk Programming Language (1988) [pdf] by ajross on Thursday May 24, 2018 @12:55AM (#17141197)
To be clear: I like that about it too. But in the real world, we want tooling that does more stuff. In the mid-90's, "everyone" knew perl, because it was the best choice for problems in this space. And in a world where everyone knows perl, there is no place for awk.

But now we live in a world where no one knows perl, and languages like python and javascript are clumsy and weird in this space. And that makes awk look clever and elegant.

All I'm saying is that in perl-world (which was a real place!), awk wasn't clever and elegant, it was stale and primitive. And that to me is more surprising than awk's cleverness.

Re:The Awk Programming Language (1988) [pdf] by fiddlerwoaroof on Thursday May 24, 2018 @01:01AM (#17141218)
I think people underestimate the importance of medium-powered tools. Perl is great, but awks limitations make it easier to write in a way that the next person can maintain.
Re:The Awk Programming Language (1988) [pdf] by fiddlerwoaroof on Thursday May 24, 2018 @01:03AM (#17141223)
That being said, the couple times I’ve paired with a perl wizard were revelatory.
Re:The Awk Programming Language (1988) [pdf] by zmodem on Thursday May 24, 2018 @02:54AM (#17141627)
Or just reading about perl wizardry: https://www.hanshq.net/perl-oneliners.html
Re:The Awk Programming Language (1988) [pdf] by xyrouter on Thursday May 24, 2018 @02:07AM (#17141466)
Can you elaborate this? What revelations did you experience?
Re:The Awk Programming Language (1988) [pdf] by ams6110 on Thursday May 24, 2018 @09:08AM (#17143575)
> in a world where everyone knows perl, there is no place for awk.

And yet in 2018, I never think about Perl anymore, but use sed, awk, and grep daily.

Re:The Awk Programming Language (1988) [pdf] by mbubb on Friday May 25, 2018 @04:01PM (#17157358)
This is a great point
Re:The Awk Programming Language (1988) [pdf] by kamaal on Thursday May 24, 2018 @04:03AM (#17142005)
>>And that makes awk look clever and elegant.

Eventually the cycle will repeat again. The moment you will have non trivial text work to do, awk will have to give way to Perl.

The rise of Python was really use case for dealing with standard interfaces like DBs/XMLs/JSONs becoming common. Python hasn't actually replaced Perl in any meaningful way.

Re:The Awk Programming Language (1988) [pdf] by oblio on Thursday May 24, 2018 @04:31AM (#17142152)
Most modern distributions write their tools in Python instead of Perl. Proof: the really long transition process Fedora (and therefore RHEL), Debian and Ubuntu went through to migrate from Python 2 to 3. They could have done it faster if not for their system tools written in Python 2.

In the web space, Python is not huge, but it definitely supplanted the niche Perl used to have. No one I know writes web stuff in Perl anymore.

Re:The Awk Programming Language (1988) [pdf] by kqr on Thursday May 24, 2018 @03:16AM (#17141742)
I totally see your point. And in Perl-world, I would probably use Perl too – I mean, if both tools are equally ubiquitous, why not use the most powerful one?

I entered the field at the tail end of the Perl era, so I've only toyed with it a long time ago.

Re:The Awk Programming Language (1988) [pdf] by mozumder on Thursday May 24, 2018 @04:39AM (#17142192)
I hated perl in the mid-90's, and stuck with grep/awk/sed intead, because it was a little more documented-structured.

Meanwhile, if you randomly mashed on your keyboard, it would output a perl script.

I jumped to Python as soon as I found out about it in the late 90's, because it was exactly what I was looking for in self-documenting structuring. It was great for creating parsers with state-machines. I was also the user of my scripts, and I didn't want to have to relearn what I coded a year or so earlier. Python let me pick that up, and to a lesser extent, awk. State machine programming was really self-documenting in Python.

Re:The Awk Programming Language (1988) [pdf] by singingfish on Friday May 25, 2018 @06:05PM (#17158405)
I’m sick of the “perl is line noise” narrative. https://pastebin.com/C9hPS8xR
Re:The Awk Programming Language (1988) [pdf] by dannas on Thursday May 24, 2018 @01:58AM (#17141441)
Here's a picture of the AWK book next to the Camel book https://twitter.com/heinrichhartman/status/77170643345276928...

"#awk doc shows you how to implement a rel-DB and a compiler. #perl doc talks 20p+ about nested data structures."

Re:The Awk Programming Language (1988) [pdf] by FractalLP on Thursday May 24, 2018 @06:55AM (#17142796)
That is one thing I like better in Python than in Perl. In Perl, I was having difficulty with nested data structures and then realized this was something I did in Python daily without even knowing it was a thing on a conscious level. Who hasn't made some weird dictionary with its values being lists or tuples or something like that?
Re:The Awk Programming Language (1988) [pdf] by ajross on Thursday May 24, 2018 @09:02AM (#17143523)
This is exactly backwards to my eyes. Perl's autovivification behavior (assigning through a empty reference to something autocreates the object of the right type) makes nested data much, much cleaner.

Who hasn't made some weird dictionary with its values being lists and forgotten to check for and write code to create it when it doesn't exist, and had to fix that later after a runtime crash? In perl that's literally covered by the one-line assignment you used to set the field you parsed.

This is why it's sad that everyone's forgotten perl.

Re:The Awk Programming Language (1988) [pdf] by kqr on Thursday May 24, 2018 @04:19PM (#17147982)
Defaultdicts to the rescue! But I think it should be an explicit choice. If you only intend to have lists at some keys, and then accidentally mistype a key, it shouldn't (in my opinion) silently create a list, effectively hiding the bug.
Re:The Awk Programming Language (1988) [pdf] by FractalLP on Thursday May 24, 2018 @04:00PM (#17147740)
Sorry, but I didn't catch your example. Can you explain a little more? What does Perl do better there?
Re:The Awk Programming Language (1988) [pdf] by kamaal on Thursday May 24, 2018 @03:56AM (#17141967)
Most of awk's 'advanced and hard to do' use cases in Perl go like

    open (my $FILEHANDLE, '<', $file) or 
        die "Cannot open $file\n";
    while(<FILEHANDLE>) {
        chomp;
        #Do you stuff here
    }
    close(FILEHANDLE);
Also perl can do various other things awk just can't. For example removing something from a file and then talking to a database or a web service, or do other stuff like parse a JSON or XML. Deal with multiple files, or other advanced use cases. Unicode work, advanced regexes etc etc.

In fact the whole point of Perl was Larry wall reaching the upper limits of what one could do with awk, sed and other utilities and having to use them all over the place in C. Then realizing there was a use case for a whole new language.

Re:The Awk Programming Language (1988) [pdf] by greenleafjacob on Thursday May 24, 2018 @04:23AM (#17142109)
In fact the boilerplate you describe is mostly redundant if you use perl -p since perl -p results in your program running with this wrapper:

    LINE:
    while (<>) {
	...		# your program goes here
    } continue {
	print or die "-p destination: $!\n";
    }
Re:The Awk Programming Language (1988) [pdf] by flukus on Thursday May 24, 2018 @08:45PM (#17149773)
Correct me if I'm wrong, but this will only be line based won't it? As far as I can tell there is no equivalent of FS/RS/OFS/ORS that make awk the record (not line) based language it is.
Re:The Awk Programming Language (1988) [pdf] by Annatar on Thursday May 24, 2018 @06:45AM (#17142740)
For example removing something from a file and then talking to a database or a web service,

...

Deal with multiple files, or other advanced use cases.

I do exactly this every day with AWK. Solving exactly these kinds of problems features prominently in the AWK programming language book.

Re:The Awk Programming Language (1988) [pdf] by kamaal on Thursday May 24, 2018 @09:02AM (#17143519)
It goes further. Awk is when you entire use case fits into the category of iterating lines in a file.

Perl is that plus more things.

Re:The Awk Programming Language (1988) [pdf] by Annatar on Thursday May 24, 2018 @09:37AM (#17143812)
Perl simply isn’t worth it. In all the decades of programming, I’ve yet to run into a problem which could only be solved in Perl because it couldn’t be done in AWK.

And I would hereby like to remind you that every computing problem is fundamentally an input-output problem, and because of this intrinsic property, it is possible to reduce all problems in computing to input-processing-output.

Which is exactly the kind of problem AWK is designed to address.

And AWK doesn’t work with lines, it works on records, for which the fathers of the language cleverly chose the default of ‘\n’, which is reconfigurable.

Re:The Awk Programming Language (1988) [pdf] by textmode on Thursday May 24, 2018 @11:44AM (#17145109)
"In all the decades of programming, I've yet to run into a problem which could only be solved in Perl because it couldn't be done in AWK."

Have you ever pondered the number of projects that, in addition to sh, make and common base utilities, require perl during compilation where awk could have sufficed?

As a single example, have you looked at compiling openssl without perl, using awk instead?

Whenever I see a perl prerequisite I question whether it is truly a requirement or whether other base utilities1 such as awk could replace it.

Assuming it could be removed, how much effort is one willing to expend in order to extinguish a perl dependency?

1. Some OS projects like OpenBSD make perl a base utility.

Re:The Awk Programming Language (1988) [pdf] by Annatar on Thursday May 24, 2018 @12:02PM (#17145291)
The illumos project undertook a massive effort to eradicate any and all dependencies on Perl (which had also been made part of the core operating system decades prior, by themselves no less). While they're still at it, they have managed to rip out most of it and replace it with binary executables in C or shell.

Yes, writing a build engine in AWK would be perfectly doable, but the right tool for that job is Make.

Re:The Awk Programming Language (1988) [pdf] by kamaal on Monday May 28, 2018 @02:29AM (#17170875)
That's easy to do.

But that's not the end of it. The whole point of Perl is avoid a salad of C and shell utils. Also in many cases the moment you have to deal with >2 files at a time shell utilities begin to show their limits.

The resulting code is often far more unreadable than anything you will ever write in Perl.

Re:The Awk Programming Language (1988) [pdf] by Annatar on Tuesday May 29, 2018 @05:54AM (#17177772)
I’m sorry you believe that, but it’s simply not true, especially since UNIX is designed to be driven by a combination of binary code and shell executables. Perl is a mess whose syntax borders on hieroglyphic once poured into software. That doesn’t mean that it’s not a capable language; but it’s not a language in which written programs are maintainable or easily debuggable.
Re:The Awk Programming Language (1988) [pdf] by tannhaeuser on Thursday May 24, 2018 @01:47AM (#17141398)
That, and awk programs are almost perfectly portable across awk implementations: nawk, gawk, mawk (can't vouch for busybox-awk as I haven't tested it, though I've heard it's good as well).

This is of practical importance for portable scripts, since Debian uses mawk [1], RH ships gawk, and Mac OS uses nawk.

[1] mawk has recently received new commits by its original author after a hiatus of 20 years or so; see https://github.com/mikebrennan000

Re:The Awk Programming Language (1988) [pdf] by jhbadger on Thursday May 24, 2018 @08:31AM (#17143287)
AWK seems far more modern than Perl, though. Defining a function with you know, "function" and actually having parameters with names feels like a 21st century language. Calling things "sub" and having it work off a an array called @_ doesn't. Yes, I know there are packages to add named parameters to Perl, plus Perl6 has them out of the box, but it is weird that things went backwards in a lot of ways when Perl replaced AWK in the mid 1990s.
Re:The Awk Programming Language (1988) [pdf] by stevekemp on Thursday May 24, 2018 @12:40PM (#17145757)
(g)awk was also fun to fuzz, recently:

https://blog.steve.fi/if_line_noise_is_a_program__all_fuzzer...

Though sadly still unfixed:

https://bugs.debian.org/816277

Re:The Awk Programming Language (1988) [pdf] by kqr on Thursday May 24, 2018 @11:18AM (#17144829)
You have a really good point. AWK feels incredibly modern for being so old.
Re:The Awk Programming Language (1988) [pdf] by kazinator on Thursday May 24, 2018 @11:27AM (#17144936)
Until you find that it has no local variables other than function parameters. In a function, local variables can be simulated by defining additional arguments ... and not passing those. Everything that isn't a function parameter is a global!

Awk is stupidly confused whether it is a two-namespace or one-namespace language (think Lisp-2 vs. Lisp-1). For instance, this works:

  function x()
  {
    print "x called"
  }

  function foo(x)
  {
    x() # function x, not parameter x.
  }
but in other situations the two spaces are conflated. For instance sin = 3 is a syntax error because sin is the built-in sinusoid function, even though you're using it as a variable, which shouldn't interfere with function use like sin(3.14).
Re:The Awk Programming Language (1988) [pdf] by coliveira on Thursday May 24, 2018 @02:03PM (#17146611)
Actually what you show is that there is a clear rule. First, the symbol is treated as a function. If it is not in the function space, then it is used as a variable name. To make a finer distinction awk would need some form of local variable declaration, which it clearly hasn't.
Re:The Awk Programming Language (1988) [pdf] by kazinator on Thursday May 24, 2018 @03:58PM (#17147718)
> First, the symbol is treated as a function. If it is not in the function space, then it is used as a variable name.

That is simply not the case. x() unambiguously treats x as a function, and will fail if there is no such function, even if there is a variable x.

  $ awk 'function foo(x)
         {
           x()
         }

         BEGIN { foo(42) }'
  awk: cmd. line:2: fatal: function `x' not defined
> To make a finer distinction awk would need some form of local variable declaration, which it clearly hasn't.

Also not the case. The purely syntactic context distinguishes whether or not the identifier is being used as a variable or function. Awk sometimes uses it, sometimes not. This doesn't diagnose:

  function x()
  {
  }

  function foo(x)
  {
     x()   # function call allowed
     x = 3 # assignment allowed
  }       
 
  BEGIN { foo(42) }

But:

  function foo(x)
  {
  }       
 
  BEGIN { foo = 3 }

  fatal: function `foo' called with space between name and `(',
  or used as a variable or an array
Why isn't it a problem that the function x() is used as a variable?
Re:The Awk Programming Language (1988) [pdf] by tannhaeuser on Thursday May 24, 2018 @11:35AM (#17145028)
Awk is basically what JavaScript syntax is based on (no really!). The following (while not terribly useful) is both awk and JavaScript:

    function f(x, otherArgs) {
      r = otherArgs["x"]
      for (v in otherArgs)
        delete otherArgs[v]
      return r
    }
JavaScript even uses awk-style regexp literals (though with PCRE semantics, and more features, etc.).
Re:The Awk Programming Language (1988) [pdf] by walshemj on Thursday May 24, 2018 @05:14AM (#17142331)
And Perl is 1000% better than awk/sed when my company got switched to unix based systems we all got sent on a weeks crash course this included sed and awk.

I have only used sed once to edit the passwd file on an early linix system when vi wasn't installed and awk never. Though having being trained in sed and awk helped with picking up Perl

Re:The Awk Programming Language (1988) [pdf] by olskool on Thursday May 24, 2018 @01:02AM (#17141222)
Python was never intended to replace Perl. Perl was designed to extract stuff from text files. Python was designed as a scripting language for system programming. IM(Seldom Humble)O Python beat Perl for two reasons (a) batteries included (CPAN became a clusterfuck) (b) C API lead to stuff like SciPy, NumPy and Pandas.

FWIW I've used both Perl and Python professionally and Python rules.

Re:The Awk Programming Language (1988) [pdf] by reacweb on Thursday May 24, 2018 @04:13AM (#17142065)
Perl is a little older than Python. Most of the ideology of Python was a reaction against Perl (https://wiki.python.org/moin/TOOWTDI). Python has always tried to be as good as Perl on everything. I use very much Perl for what it was intended: parsing files (often log files and configuration files), producing reports and launching commands (shell replacement). I have tried to use Python for the same tasks, in particular when some of the files were in xml (xml parsing in Python is nicer than in Perl). Regular expression usage is easier in Perl where multithreading is easier in Python. IMHO, the main handicap of Python vs Perl is the lack of autovivification. Python is very good for teaching (whiteboard interview) or as a scripting language around some big libraries (like tensorflow). At my work, the small glue scripts are almost always in shell or in Perl. The Python applications are being rewritten in Java because of maintenance issues (mainly caused by lack of proper typing). Python does not rule here.
Re:The Awk Programming Language (1988) [pdf] by busterarm on Thursday May 24, 2018 @04:29AM (#17142144)
You might want to try Ruby for some of those things you reached to Python for. It takes direct inspiration from Perl and does a lot of those things better, IMO.

Nokogiri is hands-down the best tool for dealing with XML that there is.

I have much the same experience with Python and anything significant developed in Python here ends up getting rewritten in Go.

Re:The Awk Programming Language (1988) [pdf] by Sileni on Thursday May 24, 2018 @08:26AM (#17143254)
Not to move the post, but that's part of what makes python so great to me. It reads like pseudocode if written with that goal in mind. Its more like having a conversation with the computer. When I need performance, I now have the algorithm written out in an easy to parse way. Then small parts in golang/C are far faster to write, because I can feel out the whole program.

Im not directly in the software industry though, just writing programs for data analysis in quality and safety programs. I'm sure once you can think directly in something like Go, it'd be faster to write that program first. But it decreases the cognitive load for me.

Re:The Awk Programming Language (1988) [pdf] by busterarm on Thursday May 24, 2018 @08:41AM (#17143354)
No worries -- I actually agree with you. We actually don't do very much scripting at my company in general -- Java, Go and JS (for Lambda) are roughly what we've standardized on.

We have a bunch of Python scripts for operations work and it's rare that performance becomes a major concern (...except in/regarding Ansible). Development isn't my team's primary responsibility so this state of things is fine -- our SysEng team can grok Python pretty well, whereas with other languages I wouldn't say this is true.

Re:The Awk Programming Language (1988) [pdf] by marklgr on Thursday May 24, 2018 @01:42AM (#17141377)
To me, the main reason of Python success vs Perl is that it's much easier to learn, so anyone can jump in even with limited programming experience.
Re:The Awk Programming Language (1988) [pdf] by mannykannot on Thursday May 24, 2018 @06:55AM (#17142797)
That is probably true with regard to its adoption, but, as a Perl fan and user, I have to say that in addition, the limitations of Perl 5's syntax begin to show once you get in to collections of collections, and passing them to functions. If you are doing this sort of thing every day, it becomes second nature, but as a casual, ad-hoc user, it is no longer in my working memory.

Maybe Perl 6 fixes these things, but learning it is too far down on my to-do list, where it sits just below Ruby.

If I have a problem that can be solved by looping through the lines of a text file and applying some combination of regular expression matching and substitution, the split and join functions, simple arrays and hash tables, I reach for Perl 5.

Re:The Awk Programming Language (1988) [pdf] by bionoid on Thursday May 24, 2018 @07:12AM (#17142868)
> Python beat Perl for two reasons [...]

The reason I personally left Perl was the extremely hostile community. When someone asked a simple question, not only would they get an overhaul and namecalling, but so would anyone that tried to help them.

Python seemed to do a much better job at onboarding new people. To me, that seems like the most important reason they won in the long run.

Re:The Awk Programming Language (1988) [pdf] by liveoneggs on Thursday May 24, 2018 @01:34PM (#17146313)
that is a very abnormal experience. Larry Wall has personally helped me with at least two junior issues over the years by just randomly answering in general forums.

FWIW perl6 takes extra special effort to be nice.

Re:The Awk Programming Language (1988) [pdf] by bionoid on Friday May 25, 2018 @08:35AM (#17152977)
> that is a very abnormal experience.

I don't have links handy, but there were official blog posts and such about how they endeavored to fix the problem. Of course I'm not saying it was universal, nor trying to take away from the fact that there are a lot of great people in the Perl community (PerlMonks is a good example)

They did fix it, as far as I can tell anyway, but it was too little too late.

Re:The Awk Programming Language (1988) [pdf] by collyw on Thursday May 24, 2018 @05:28AM (#17142400)
>CPAN became a clusterfuck

Did it? Not used Perl for a while but I never needed to worry about backward compatibility and versions with CPAN, while I find I do with Python (to be fair I am programming more complex stuff than I did in my Perl days).

Re:The Awk Programming Language (1988) [pdf] by FractalLP on Thursday May 24, 2018 @06:47AM (#17142748)
I've used Python for years and a little Perl. CPAN works pretty well when used with ActiveState...not sure about Unix. Python on Windows stinks when using Pip and there is some VisualStudio C++ library dependency you need and they don't even have anymore. With Python it is best to get a large distribution that bundles everything already such as Anaconda...not worth the hassle.
Re:The Awk Programming Language (1988) [pdf] by ivanhoe on Thursday May 24, 2018 @06:53AM (#17142783)
IMO Python won primarily because its syntax was more English-like, which makes it a lot easier and more readable to regular people who never worked with shell and linux, and perl's $#@%>> and regExps confused the hell of them. That and the boom of PHP killed Perl 5 popularity, while python got its foot in the door in science/finance niches and survived.
Re:The Awk Programming Language (1988) [pdf] by Zash on Thursday May 24, 2018 @07:09AM (#17142859)
> CPAN became a clusterfuck

This gave me flashbacks to installing some perl module and watching it download half of CPAN.

Re:The Awk Programming Language (1988) [pdf] by olskool on Friday June 01, 2018 @05:33PM (#17210581)
Just as bad I'd download CPAN module A then CPAN module B and CPAN would totally trash A.
Re:The Awk Programming Language (1988) [pdf] by vgy7ujm on Thursday May 24, 2018 @07:30AM (#17142966)
Still NPM is so much worse...
Re:The Awk Programming Language (1988) [pdf] by Zash on Saturday May 26, 2018 @11:50AM (#17162654)
Those who don't learn from history etc.
Re:The Awk Programming Language (1988) [pdf] by conner_bw on Thursday May 24, 2018 @02:38AM (#17141570)
> forgot perl

Or maybe, hiding out in PHP?

Steeling syntax, releasing versions bigger than 5, smoking regex benchmarks...

https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

Re:The Awk Programming Language (1988) [pdf] by tannhaeuser on Thursday May 24, 2018 @06:45AM (#17142733)
> And the scary syntax is all in the Rust world.

JavaScript is heading in the direction of Haskell, Scala, and (to a lesser extent) Rust, too [1].

[1]: https://medium.freecodecamp.org/here-are-three-upcoming-chan...

Re:The Awk Programming Language (1988) [pdf] by MichaelMoser123 on Thursday May 24, 2018 @09:36AM (#17143804)
Perl5 and perl6 are very different languages - however after perl5 there was nobody left to listen... (Disclaimer: I got used to perl5 and I still think it's quite reasonable)
Re:The Awk Programming Language (1988) [pdf] by justwalt on Thursday May 24, 2018 @09:27AM (#17143743)
I didn’t know Perl was capable of filling the same niche as awk, and I think awk is absolutely wonderful. How does Perl improve on it?
Re:The Awk Programming Language (1988) [pdf] by vasili111 on Thursday May 24, 2018 @11:22AM (#17144865)
What about tcl? Is it better than perl for text proccessing
Re:The Awk Programming Language (1988) [pdf] by xyrouter on Thursday May 24, 2018 @02:13AM (#17141486)
If a 25 year old programmer were to start learning Perl now, what would you recommend: Perl 5 or Perl 6?
Re:The Awk Programming Language (1988) [pdf] by jdoege on Tuesday May 29, 2018 @09:50AM (#17179124)
If you are doing it for personal growth and learning, then Perl 6. It is an interesting language that cleanly supports many major programming paradigms including functional, imperative and object oriented and, most probably, others. Additionally, it has many nifty features built in such as concurrency, grammars and rationals. Aside from that, it is also fun to use and has a great community.

If you are doing it for immediate application in a job or wish to acquire a skill you think might be required in a job then the answer is probably Perl 5. Despite the noise about Perl, it is still used a lot in many industries for flow control and inter-tool format conversion as well as many other applications. Many, many people understand perl and use it for rapid development of automation tools. I can tell you for a fact that it is pervasive in the semiconductor industry and is practically a job requirement, there.

Re:The Awk Programming Language (1988) [pdf] by FractalLP on Thursday May 24, 2018 @07:19AM (#17142913)
Perl6 is mostly complete. Even though it has been getting significant weekly performance improvements (they have a weekly summary of these things), it still has a long way to go. It has a lot of really cool things such as simple to use concurrency, grammars, gradual typing...etc. It is a big language, but not super hard to learn. A bunch of books have been released on it in the past two years. Perl5 is used by companies now. Some are choosing to write new software in it, but there is a lot of legacy apps.

Remember that they are two different languages with some similarities. Perl6 has really good support for making big apps I would say as it has really good OO support out of the box in addition to making FP concepts easy too. Perl5 has atrocious support baked in, but they have the excellent libraries that everyone uses to give them world class support for OO. Still, it feels more natural in Perl6.

On another note, Groovy is another great and fast language that runs on the JVM and works very well in the scripting space with a lot of DSLs for GUI, XML, DB...cool stuff.

Re:The Awk Programming Language (1988) [pdf] by vorg on Thursday May 24, 2018 @03:52PM (#17147666)
> On another note, Groovy is another great and fast language that runs on the JVM and works very well in the scripting space

But the same versioning issue exists for Apache Groovy (2 or 3 ?) that exists for Perl (5 or 6 ?). The Groovy PMC seem to be handling the issue, though, by slowing down the development of Groovy 3 to a crawl so it won't ever ship.

Oh, and calling Groovy "fast" is a bit of a stretch. It hardly matters anyway because scripting for classes written in Java doesn't need "fast".

Re:The Awk Programming Language (1988) [pdf] by cygx on Thursday May 24, 2018 @03:22AM (#17141782)
Depends on what you're looking for:

In many ways, p6 is the superior language. But as an AWK competitor specifically, p5 might be the better choice for performance reasons alone (while p6 has been improving, as far as regex performance goes, it just isn't there yet [1]). You might even be able to write tighter code in p5 (for one, p6 regexes return objects, not strings, so in cases where you actually want the latter, you'll have to throw in boilerplate).

[1] https://gist.github.com/cygx/9c94eefdf6300f726bc698655555d73...

Re:The Awk Programming Language (1988) [pdf] by v_lisivka on Thursday May 24, 2018 @07:31AM (#17142973)
Perl6 has grammars: https://docs.perl6.org/language/grammar_tutorial (recursive regex with sane syntax), which are much better than plain regex in many cases. Otherwise modern Perl5 is much more practical.
Re:The Awk Programming Language (1988) [pdf] by zimpenfish on Thursday May 24, 2018 @04:40AM (#17142198)
If you want to get paid for doing it, Perl 5. If you're just mucking about with personal projects, Perl 6.
Re:The Awk Programming Language (1988) [pdf] by nur0n on Thursday May 24, 2018 @02:20AM (#17141511)
Perl 5 and Perl 6 are two different beasts. Perl 5 is closer in spirit to Awk.
Re:The Awk Programming Language (1988) [pdf] by mdip on Thursday May 24, 2018 @08:41AM (#17143359)

    it always blows my mind that so few people really know how to use it at a decent level
I'll second this -- it's by far the most used swiss-army knife in my arsenal[0]. A little part of me dies when I see scripts doing grep|awk, using awk simply to print a column. After taking some time to actually read the gawk user manual a few years ago, I've found that I can do most things in awk that I was previously using grep/sed (and to a lesser extent) perl/python for in the shell. In my environment, it also comes with the benefit that I know the awk code I'm writing is supported by the version of gawk that's installed on every server/computer I come into contact with -- no having to ensure the right python/perl is available.

One thing I wish there was better documentation on, though, is creating complete gawk scripts. With @include directives coupled with AWK_PATH, it's really convenient to build up a handful of utility functions that do frequent things and I've found, on several occasions, that I end up writing an .awk script instead of a bash/zsh script and it ends up being a much more straight-forward set of code.

[0] Well, specifically, the 'gawk' variant

Re:The Awk Programming Language (1988) [pdf] by ausjke on Thursday May 24, 2018 @08:49AM (#17143415)
why not write something about the @include directives like a blog or some posts, that will be awesome.
Re:The Awk Programming Language (1988) [pdf] by busterarm on Thursday May 24, 2018 @04:38AM (#17142188)
I think my tendency to reach for grep/sed/awk might be the thing that led me away from software development full-time and into the ops world.

Too many times I encountered 200+ line Python scripts that I could replace with an Awk one-liner and a cron job.

My lazy habit in my Ruby work eventually became to parse JSON/XML/whatever into usable text, shelling out to sed/awk and working with the results. This would not only save me LoC, but was less error-prone.

Re:The Awk Programming Language (1988) [pdf] by taeric on Thursday May 24, 2018 @12:19AM (#17141058)
I think my hiccup is that it seems like good awk programmers are expected to be able to pass the full bloody program in as a simple string argument in a bash one-liner. Which is clearly not tenable.

There are a few things I have done which felt more difficult than they should. However, the vast majority of dealing with structured data using awk really has been a pleasant surprise.

Re:The Awk Programming Language (1988) [pdf] by Stratoscope on Thursday May 24, 2018 @02:33AM (#17141552)
Awk did have this reputation of hard-to-read one liners, but it was also always possible to write readable code in it much as you would do in any language.

My favorite bit of Awk code that I ever wrote was this print formatting program for the HP LaserJet II:

https://github.com/geary/awk/blob/master/LJPII.AWK

It printed source code in a "2-up" format, with two pages printed side by side in landscape mode. It looked for the kind of separators that I and many people were fond of back in those days (the source code is a good example) and converted those to graphic boxes. And it tried to be smart about things like breaking pages before a comment box, not after.

I wish I still have a sample printout handy. For 300 lines of what I thought was fairly cleanly written Awk code, it made some nicely formatted printouts.

Re:The Awk Programming Language (1988) [pdf] by oblio on Thursday May 24, 2018 @05:41AM (#17142466)
That's very clean looking code and I think it would be considered so regardless of the language it was written in, IMHO. Nice! :)
Re:The Awk Programming Language (1988) [pdf] by coliveira on Thursday May 24, 2018 @01:07AM (#17141243)
Awk makes it easy to write one liners, but it is also very easy to save your script to a file and run it with the -f option.
Re:The Awk Programming Language (1988) [pdf] by schoen on Thursday May 24, 2018 @01:00AM (#17141216)
I think some of the examples in popular documentation use awk -f to read a program from a file, so I don't feel like that's regarded as an unreasonable way to run awk code.

It's true that many programs might well just have a single action (or a single action plus a BEGIN and END), but I'm not sure that resorting to awk -f will give great offense.

Re:The Awk Programming Language (1988) [pdf] by asicsp on Thursday May 24, 2018 @12:35AM (#17141125)
one-liners are fun though, especially if you like code golfing..

if you're interested, you could give my tutorial(https://github.com/learnbyexample/Command-line-text-processi...) a try

it has over 300 examples..

Re:The Awk Programming Language (1988) [pdf] by natecavanaugh on Thursday May 24, 2018 @01:47AM (#17141395)
I gotta say, I really enjoyed skimming through this, and saving it for future reference. I can already tell there are some basic things that I should've memorized with all the one liners I've used, but because most were cobbled together for the immediate task (and many online forum searches assume a lot of prior knowledge), so t this presentation, and cookbook style references really help me hold the practical benefits in memory alot longer, so thanks again!
Re:The Awk Programming Language (1988) [pdf] by asicsp on Thursday May 24, 2018 @02:42AM (#17141583)
thanks, that means a lot to me :)

if you are interested in text processing in general, do check the other chapters for grep/sed/perl/sort/paste/pr/etc

I learned a lot writing them up and marvel at the speed and functionality provided by these tools.. for many cases, it is lot easier to write a bash script combining these tools than to write a Perl/Python/Ruby script..

Re:The Awk Programming Language (1988) [pdf] by xpil on Thursday May 24, 2018 @06:47AM (#17142749)
Ahh, what a useful link! Bookmarking immediately. I use AWK like once a year but when I do, I usually struggle a lot. Your examples are really helpful!
Re:The Awk Programming Language (1988) [pdf] by asicsp on Thursday May 24, 2018 @07:43AM (#17143021)
thanks, it's a reference for me as well - not easy to remember all the features and tricks
Re:The Awk Programming Language (1988) [pdf] by ageofwant on Thursday May 24, 2018 @01:45AM (#17141389)
Thanks for that mate. I'm a regular customer your work is greatly appreciated.
Re:The Awk Programming Language (1988) [pdf] by asicsp on Thursday May 24, 2018 @02:44AM (#17141587)
thanks for the feedback :) happy learning
Re:The Awk Programming Language (1988) [pdf] by pmarin on Thursday May 24, 2018 @04:01AM (#17141990)
what I usually do is to wrap the awk script in to a sh function. I never do one-liners unless it is a well known idiom.
Re:The Awk Programming Language (1988) [pdf] by wernsey on Thursday May 24, 2018 @12:05PM (#17145322)
One thing I also really like about Awk is that you can keep 99% of the language in your head. With Awk it is seldom necessary to even reference the man page. I don't have to interrupt myself with looking up the syntax or the order of the parameters to a function.
Re:The Awk Programming Language (1988) [pdf] by gnuvince on Thursday May 24, 2018 @08:03AM (#17143132)
Agreed. I learned awk a bit late in my Linux journey (started using Linux in 1999, learned awk in 2016), but I can't imagine not using it daily now. Great tool to manipulate data, and it's great for when you want a Unix tool that doesn't exist (e.g., computing the sum or mean of a stream of numbers).
Re:The Awk Programming Language (1988) [pdf] by boobsbr on Thursday May 24, 2018 @05:15AM (#17142336)
I never got past using awk for string replacement that I couldn't pull off as a regex in grep...
Re:The Awk Programming Language (1988) [pdf] by gitgacutils on Thursday May 24, 2018 @01:59PM (#17146561)
awk is a fundamental part of the unix ecosystem. It's in the hall of fame of utils along with the likes of grep. If you use unix or linux in any semi-serious capacity, you are familiar with awk.
Re:The Awk Programming Language (1988) [pdf] by Annatar on Thursday May 24, 2018 @06:36AM (#17142695)
I use AWK daily; it’s my workhorse programming language and automation tool. Small, fast, no dependencies and portable.

Extremely powerful programming language for big data processing and data driven programming, I often use it to generate shell scripts based on some arbitrary data. With no memory management and providng hash arrays, AWK is an absolute delight to program in. Using it with the functional programming paradigm makes it even more powerful. It blows my mind that Aho, Weinberger and Kernighan managed to design something so versatile and yet so small and fast. I’ve also been using it to replace Python scripts with a ratio of Python:AWK being anywhere from 3:1 to 10:1 as far as lines of code needed to get the same tasks done.