LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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: Slackware
Posts: 8,236

Rep: Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344
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,209

Rep: Reputation: 705Reputation: 705Reputation: 705Reputation: 705Reputation: 705Reputation: 705Reputation: 705
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: CentOS
Posts: 3,939

Rep: Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717
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<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,667
Blog Entries: 6

Rep: Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531Reputation: 2531
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: 9,078
Blog Entries: 4

Rep: Reputation: 3166Reputation: 3166Reputation: 3166Reputation: 3166Reputation: 3166Reputation: 3166Reputation: 3166Reputation: 3166Reputation: 3166Reputation: 3166Reputation: 3166
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: Slackware
Posts: 8,236

Original Poster
Rep: Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344
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: Slackware
Posts: 8,236

Original Poster
Rep: Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344
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: CentOS
Posts: 3,939

Rep: Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717Reputation: 1717
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
Senior Member
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: AntiX
Posts: 2,348

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 Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 11,017

Rep: Reputation: 3275Reputation: 3275Reputation: 3275Reputation: 3275Reputation: 3275Reputation: 3275Reputation: 3275Reputation: 3275Reputation: 3275Reputation: 3275Reputation: 3275
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, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 13,699
Blog Entries: 22

Rep: Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601Reputation: 3601
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: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 6,791
Blog Entries: 12

Rep: Reputation: 2422Reputation: 2422Reputation: 2422Reputation: 2422Reputation: 2422Reputation: 2422Reputation: 2422Reputation: 2422Reputation: 2422Reputation: 2422Reputation: 2422
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: Slackware
Posts: 8,236

Original Poster
Rep: Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344Reputation: 3344
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: Slackware
Posts: 8,236

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration