LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Should I make "learn AWK" a 2018 resolution? (https://www.linuxquestions.org/questions/programming-9/should-i-make-learn-awk-a-2018-resolution-4175620388/)

dugan 12-27-2017 12:42 PM

Should I make "learn AWK" a 2018 resolution?
 
Is AWK still useful these days?

Every time I see AWK, I just think I need to rewrite it in Python.

keefaz 12-27-2017 12:45 PM

It's good at getting fields/columns from text

rknichols 12-27-2017 01:14 PM

The whole awk manual is just 23 pages. Contrast that with Python, ... .

astrogeek 12-27-2017 01:28 PM

I got by without it (avoided it) for a long time, using other scripting languages for anything sed alone could not handle.

Then after seeing my then young son slice and dice circles around some of my solutions with awk, I decided to finally learn it...

It turned out to be very simple, at least the basics. You undoubtedly know regular expressions already, so you mostly need to grasp the awk processing loop, how it separates and references fields and variables, plus a few basic built-in functions, and you will begin to use it for many simple and complex tasks without much thought.

You will gain proficiency with use, as with all programming languages. So learn the basics and start using it - it grows on you quickly in my experience!

sundialsvcs 12-27-2017 01:41 PM

Although I would of course categorically say that "you should always familiarize yourself with yet-another tool," I would also add to this particular comment that "I often find myself using Perl, instead."

The Perl programming language really started, long ago, when a guy named Larry Wall decided that "awk" wasn't powerful enough for his purposes. So, he created a new tool that has very-obvious and very-strong ancestry to Awk ... so much so that there is even an a2p command for "converting Awk to Perl!" :eek:

While I happen to find this command a bit too simple-minded, the essential idea is clear ... and, to me, compelling. Perl is a far-more powerful programming environment. (Which, to its credit and in its defense, "awk never set out to be.")

All this being said, you will encounter "awk scripts" and "awk one-liners" in production code, and you therefore should familiarize yourself with this tool as-is. It is certainly a very powerful tool in its own right, and I have used it "as is" many, many times to great effect.

To me, this sort of thing isn't "a New Year's resolution." It's the work of an afternoon. You'll probably find it to be the same.

(Full disclosure: I am a 'language nerd.') But, y'know, when you are in this business as a means of earning your daily bread, it just never hurts to keep your pocket-protector as full of ideas as possible. ;) You never know when you'll need to use one, and "if you've already seen it, it makes you Look Very Cool.™" (In spite of the pocket-protector ...)

dugan 12-27-2017 02:11 PM

Quote:

Originally Posted by sundialsvcs (Post 5798471)
Although I would of course categorically say that "you should always familiarize yourself with yet-another tool," I would also add to this particular comment that "I often find myself using Perl, instead."

Not helpful. Stop doing this.

This is not the first time either.

dugan 12-27-2017 02:35 PM

Quote:

Originally Posted by rknichols (Post 5798457)
The whole awk manual is just 23 pages. Contrast that with Python, ... .

Er, which manual are you talking about? The gawk manual is 560 pages; I assume you're talking about a different one?

rknichols 12-27-2017 08:47 PM

Quote:

Originally Posted by dugan (Post 5798505)
Er, which manual are you talking about? The gawk manual is 560 pages; I assume you're talking about a different one?

The gawk manpage from "man -t gawk" is 23 printed pages. That's all it takes to describe the whole language, and it's all I've ever needed. Ditto for several people I've worked with. One can, of course, write whole books of tutorials for ways to use awk.

fatmac 12-28-2017 07:05 AM

Shell, sed, & awk used to be the mainstays of unix, they can do an awful lot of things, by themselves or using pipes to other basic unix programs like uniq, etc.

Other languages have their following, but if you learn what comes with a basic unix setup, you will be able to do things on any version of unix like OSes.

pan64 12-28-2017 11:24 AM

yes, sometimes awk is the right tool to implement a feature. perl/python/whatever obviously capable to do the same, but for simple tasks probably awk is even faster.

frankbell 12-28-2017 08:18 PM

Thers is an in-depth series on using awk at Hacker Public Radio. If you want to learn awk, you might find it most helpful.

It's on my bucket list.

rtmistler 12-29-2017 07:13 AM

It's worth using it. By using it, you will learn it. No tool is the final solution, there are different tools suitable for different solutions. I've found that awk is great for splitting text fields to allow me to search and replace.

dugan 01-22-2018 11:38 AM

Resolution kept!

Funtoo's tutorials are good.

https://www.funtoo.org/Awk_by_Example,_Part_1

dugan 01-25-2018 09:46 AM

Turns out it's great for parsing the output of stuff like xrandr, xset, glxinfo, xdpyinfo, etc.


All times are GMT -5. The time now is 03:18 PM.