Hacker News new | past | comments | ask | show | jobs | submit login
Learn Awk by Example (2019) (github.com/thewhitetulip)
250 points by thewhitetulip on March 1, 2020 | hide | past | favorite | 29 comments



As much as I admire this, I believe that The AWK Programming Language is probably the best resource for just learning awk.

https://en.wikipedia.org/wiki/The_AWK_Programming_Language

I read it on a whim after hearing the accolades awk would get from people when it came to text munging, and as I have to do a lot of it at work, I figured I'm bound to come across practical situations for my own purposes once I get a few basics from the guide.

And sure enough, I did. I love the original simply because it helped me understand the scope of tasks I should look at for awk; I could just think about my own difficulties with handling large amount of text data (mostly very verbose logging), and then create a workflow in awk that mimicked my actual work, but vastly expedited.

The article linked is nice and cute, but it more or less is a rehash of the topics covered in The AWK Programming Language, which isn't bad (more data is good), but I feel the original handles the explanations far far better and helps you to really understand what awk is good at and when to attack with awk versus when your task is better suited for something else.


Since threads like these are always filled will praise about the book, I started reading it and was quite excited about it.

The book is excellent, but the target audience it is written for won't read it today. It is written for people that pretty much have never programmed anything before. For someone that is knowledgeable of computing in general, or programming and possibly even already have a vague idea of what AWK is, it becomes very verbose.

I get it, it is a cool way to at the learn some history and the context of which it was created. But if the sole goal is to quickly learn AWK I feel that it is quite ineffective and it becomes hard to focus when there is so little relevant content.

I lost focus and didn't finish.

I would like to pick it up again in a less stressful time. The thing that holds me back is that I'm not sure I will get enough use of it to be able to remember it. It might be a simple language but it is very different from anything that at least I use today, and if I have to relearn it every other time I use it then there isn't much point to it.


Are you talking about gawk manual or the submission?



I'd also suggest the manual/book for gawk[1] which introduces the language from the basics, covers newer features and also mentions which features are unique to gawk

[1] https://www.gnu.org/software/gawk/manual/gawk.html


Agreed! I got into AWK not because I thought I needed AWK, but because I'd heard "The AWK Programming Language" was a great book ... and sure enough, it was. Like TCPL and TGoPL, all of which share Kernighan as an author, a couple of chapters in you already know most of the language, and the rest of the book is more and more complex examples with clear but dense explanations.

After reading the first few chapters of "The AWK Programming Languages", I was inspired to write an AWK interpreter in Go: https://benhoyt.com/writings/goawk/


Yes, that book is the best book there is. I myself learnt from it. But it is a little in depth.

My idea of this book was to team awk quickly. This is an intro book and after 'discovering' awk from my book, users will surely read the larger book


I can confirm this statement. The book is great and helped me understand that awk is a lot more than just a tool to select columns.


The book is available at archive.org text achrive[1]

[1] https://archive.org/details/awkprogrammingla00ahoa (borrow for 14 days)


Nice! A few suggestions if I may:

* please consider using the same prompt for all examples, a few of them start with `code` while some others start with `awk book` and some do not have any prompt at all

* split long chapters into smaller sections plus add section headings as links at the start of chapter

* please please please avoid parsing ls [1] you could either reuse `sales.csv` or create another sample file instead of using `ls` as source of input... for example, your `ls -l | awk '$NF ~ /c/ {print}'` example will not work if a file is name `code xyz` (note the space)

Also, I have a similar example based hundreds of gawk one-liners [2] tutorial, which I'm currently working towards publishing as a book this month with better examples, descriptions, new regex chapter, etc

[1] https://unix.stackexchange.com/questions/128985/why-not-pars...

[2] https://github.com/learnbyexample/Command-line-text-processi...


Thank you for your suggestions. I'll keep them in mind while updating tutorial


I think this is deliberate subversive misdirection from the Golang mafia


Hahaha I can assure you that it is not.

I have written a few books and I copied the text files from my Go book.

Apologies.

I didnt get to creating a gitbooks for this book.

I am planning to statiscally generate a website and host it via github itself, rather than gitbooks.


You wrote a great tutorial, I'm definitely saving this and sharing it with any colleagues who need help with command line file mangling.


Thank you very much.


I love having a variety of these types of sites available for a new language. Different learners will react well to different styles. My personal favorite is AWK in 20 Minutes: http://ferd.ca/awk-in-20-minutes.html

The AWK Programming Language book is also great.

Nice work.


Thank you! Yes, everyone learns in their own way. I am happy that you found the book useful

And yes. The official boom is very good and in depth


Im on the second page of this book and it is presented in a way that makes me want to use awk right now. I really like how this is written, it does a great job of presenting a base idea and building on it. @thewhitetulip did you plan out all of the example topics before writing each page in the manuscript?


Thank you very much!

My idea was to get the reader started as quickly as possible. I wrote a book which I hoped existed when I was learning awk.

I mostly learnt awk from the gawk manual and internet. So I wrote down a long list of awk commands while I learnt.

Then I sorted them according to concept and then wrote the text surrounding it


Your Gitbooks link seems to go to something about Go?



The author probably forgot to edit that file and those are default links of the template he used.


Yes, that is my Go book. I copied the template from that book thats why it happened


So is the YouTube link, the leanpub link and the code tasks link.


I can't reach anything under gitbooks.io at all. Some GDPR paranoia thing again? It would be lovely to get an HTTP 451 at least.


This has taught me something useful in a short space of time, thank you.


You are very welcome!



The "Read Online" link mistakenly points to something about Golang, not Awk.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: