News for hackers. Stuff that matters.
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.