Live data from Hacker News

Why Learn Awk? (2016)

blog.jpalardy.com

241–246 of 246 posts

Re: Why Learn Awk? (2016)

#241
post #202

Earlier quoted context omitted.

So is -F, IIRC.

-F has always been supported by real UNIX®️ AWK; that's where -v and -F come from.

BUGS The -F option is not necessary given the command line variable assignment feature; it remains only for backwards compatibility.

EXAMPLES Print and sort the login names of all users:

            BEGIN     { FS = ":" }
                 { print $1 | "sort" }
The above is from the GAWK manpage. FWIW, the first example under EXAMPLES uses FS not -F.

There is nothing wrong with using FS instead of -F.

Re: Why Learn Awk? (2016)

#242

I use awk because there's an almost 100% chance that it's going to be installed on any unix system I can ssh into. I use awk because I like to visually refine my output incrementally. By combining awk with multiple other basic unix commands and pipes, I can get the data that I want out of the data I have. I'm not writing unit tests or perfect code, I'm using rough tools to do a quick one-off job. For instance, "mail…

As part of a practical component to any software engineering degree should be a simple course on common Unix tools, covering grep, awk, sed, PCRE, and git. A little bit of knowledge here goes a LONG way.

I wholeheartedly agree. I've seen people agonize for days over results from Splunk that they want to turn into something more user-friendly. 15 minutes of messing around with the basic command line Unix tools has that information in a perfect format for their needs.

This is something I need to bring up to my coworkers, I should write some sort of basic guide to unix tools for them.

Re: Why Learn Awk? (2016)

#243
post #241

Earlier quoted context omitted.

-F has always been supported by real UNIX®️ AWK; that's where -v and -F come from.

BUGS The -F option is not necessary given the command line variable assignment feature; it remains only for backwards compatibility. EXAMPLES Print and sort the login names of all users: BEGIN { FS = ":" } { print $1 | "sort" } The above is from the GAWK manpage. FWIW, the first example under EXAMPLES uses FS not -F. There is nothing wrong with using FS instead of -F.

GAWK is not a real AWK!!! When will you people learn that GNU is not UNIX®️?

FS is not used on the command line and doing so is asking for trouble. FS is a built-in variable and as such is treated specially.

Re: Why Learn Awk? (2016)

#244
post #239

Earlier quoted context omitted.

That is not how FS is set; It's set with -F. And there is actually no need to use -v, passing variables at the end works consistently across all AWK's and always has: echo "" | awk '{print Bla;}' Bla="Hello."

What if you set FS with -F but then later in the script want to change FS to something else.

The results will be unpredictable at best; either set it with -F, or use 'BEGIN {FS = "...";}', but not both.

Re: Why Learn Awk? (2016)

#245

It would be so great if awk had a csv mode. For whatever reason (Excel), CSV seems to be the default text format for field oriented data. Maybe I’m dumb but I’ve never come up with a separator regex that is quite right.

The simple case is: FS = "," or: awk -F ',' If you're working with CSV data that has quoted strings with embedded commas, FPAT is your friend: FPAT = "([^,]+)|(\"[^\"]+\")" See: https://www.gnu.org/software/gawk/manual/gawk.html#Splitting...

just want to say thanks for this, I haven't had to deal with CSV for years and now only a week after you posted this I needed it.

brew install gawk

good to go

:)

Re: Why Learn Awk? (2016)

#246
post #204

Earlier quoted context omitted.

I’m pretty mathsy but I don’t get this

It is from relational algebra used in database theory. There is an excerpt from one of the first MOOCS offered here on Lagunitas now.[1] It is pretty intuitive once you get the hang of it. [1] https://lagunita.stanford.edu/courses/DB/RA/SelfPaced/course...

Thank you for this context
Post reply on HN