LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-27-2017, 12:42 PM   #1
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,235

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
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.

Last edited by dugan; 12-27-2017 at 01:10 PM.
 
Old 12-27-2017, 12:45 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
It's good at getting fields/columns from text
 
1 members found this post helpful.
Old 12-27-2017, 01:14 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
The whole awk manual is just 23 pages. Contrast that with Python, ... .
 
1 members found this post helpful.
Old 12-27-2017, 01:28 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
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!
 
Old 12-27-2017, 01:41 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
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!"

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 ...)

Last edited by sundialsvcs; 12-27-2017 at 01:43 PM.
 
1 members found this post helpful.
Old 12-27-2017, 02:11 PM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,235

Original Poster
Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by sundialsvcs View Post
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.

Last edited by dugan; 12-27-2017 at 02:13 PM.
 
Old 12-27-2017, 02:35 PM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,235

Original Poster
Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
Originally Posted by rknichols View Post
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?
 
Old 12-27-2017, 08:47 PM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
Quote:
Originally Posted by dugan View Post
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.
 
1 members found this post helpful.
Old 12-28-2017, 07:05 AM   #9
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,499

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 12-28-2017, 11:24 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,893

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
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.
 
Old 12-28-2017, 08:18 PM   #11
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,332
Blog Entries: 28

Rep: Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144Reputation: 6144
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.
 
1 members found this post helpful.
Old 12-29-2017, 07:13 AM   #12
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
Old 01-22-2018, 11:38 AM   #13
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,235

Original Poster
Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Resolution kept!

Funtoo's tutorials are good.

https://www.funtoo.org/Awk_by_Example,_Part_1
 
1 members found this post helpful.
Old 01-25-2018, 09:46 AM   #14
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,235

Original Poster
Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Turns out it's great for parsing the output of stuff like xrandr, xset, glxinfo, xdpyinfo, etc.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error """make:*** no rule to make target 'modules'.stop'"" SI1 Linux - Newbie 1 11-01-2017 11:57 PM
every fields make "-" delimited using awk jone kim Programming 4 09-20-2014 01:58 AM
kernel make error: "vmlinux.o no such file ..." and make -d "Reaping losing ..." micscherer Linux - Kernel 3 06-12-2012 07:29 AM
spamassassin: sa-learn --sync -> "Argument "M-HM-JM-J" isn't numeric" XXLRay Linux - Server 8 06-22-2010 10:10 AM
Changing "X resolution" to make everything smaller Yalla-One Slackware 1 12-10-2005 02:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration