Live data from Hacker News

Awk: The Power and Promise of a 40-Year-Old Language

fosslife.org

81–90 of 122 posts

Re: Awk: The Power and Promise of a 40-Year-Old Language

#81

Learning awk is actually pretty simple. For years I just used the '{print $2}' version to extract fields, but after reading some short book I felt pretty confident of having understood the basics. Sadly I don't remember which book it was, but this page looks like a good start: https://ferd.ca/awk-in-20-minutes.html

Likely the one by A, W, and K. https://news.ycombinator.com/item?id=13451454

Re: Awk: The Power and Promise of a 40-Year-Old Language

#82
post #2

HN discussion threads for some of the links mentioned in the article: * Using AWK and R to parse 25TB - https://news.ycombinator.com/item?id=20293579 * Command-line Tools can be 235x Faster than a Hadoop Cluster - https://news.ycombinator.com/item?id=17135841 * The State of the AWK - https://news.ycombinator.com/item?id=23240800 For awk alternative implementations, I'm keeping an eye on frawk [0]. Aims to be faster,…

CSV is a complicated format but that does not mean awk is incapable of dealing with it.

https://www.gnu.org/software/gawk/manual/html_node/Splitting...

https://github.com/e36freak/awk-libs/blob/master/csv.awk

https://raw.githubusercontent.com/Nomarian/Awk-Batteries/mas...

Re: Awk: The Power and Promise of a 40-Year-Old Language

#83
post #66

Earlier quoted context omitted.

I'm curious what linux distros don't have either some version of perl or python. I like awk, mind, but this is not necessarily (IME) a good argument for it.

> I'm curious what linux distros don't have either some version of perl or python. I imagine that DamnSmallLinux or TinyCoreLinux possibly don't have them by default. Their focus is to be as small as possible in order to download quickly and fit in a USB drive or CD. Their small size was more important back when speeds were slower and drives were smaller. They were also good for when you had a limited number of stora…

If you’re using DamnSmallLinux etc I’d imagine you can package your own awk quite easily! Perl would require a lot more packages. But all you need to do is copy a couple binaries right?

Re: Awk: The Power and Promise of a 40-Year-Old Language

#84
post #77

Earlier quoted context omitted.

Python definitely not, though.

Yeah, but if you are happy to program in Perl, that's basically every major Linux distro covered. Anything using DEB or RPM packaging, any machine with Git installed (which includes Windows), plus the ones I already mentioned, already have access to Perl. This is a formidable installed base with no effort needed to install a runtime.

I agree, but michaelcampbell's point seemed to be: why learn a language for its ubiquity, when more commonly used languages seem to be just as ubiquitous? So, I focused on how they're not that ubiquitous.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#85
post #83
post #66

Earlier quoted context omitted.

> I'm curious what linux distros don't have either some version of perl or python. I imagine that DamnSmallLinux or TinyCoreLinux possibly don't have them by default. Their focus is to be as small as possible in order to download quickly and fit in a USB drive or CD. Their small size was more important back when speeds were slower and drives were smaller. They were also good for when you had a limited number of stora…

If you’re using DamnSmallLinux etc I’d imagine you can package your own awk quite easily! Perl would require a lot more packages. But all you need to do is copy a couple binaries right?

Haven't used these distros since a decade or so ago.

Not sure why I'd have to package awk. Busybox's is probably sufficient for most uses, if the need ever arised, which I don't think it normally does when using these distros.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#86
post #31

I use awk constantly in bioinformatics, for many of the file formats designed to store genomic data, awk is the easiest tool you can use for processing.

I did the exact same thing!

quickly looking at averages/errors, a simple awk one-liner will do.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#87
post #28
post #23

Earlier quoted context omitted.

I had to take large CSV files like {question, right_ans, wrong_ans1, wrong_ans2, wrong_ans3} and covert them into SQL insert files. Few caveats - some could be duplicates, some characters were not allowed, and some had formatting issues. The first issue was avoided by upserting, but the other two I used Awk and Sed for and put together a fairly robust script far quicker than if I reached for Python. I probably would…

Awk is not really very good at reading complex CSVs (as defined in RFC-4180), where newlines (record separators) can appear within quoted strings. It can be done, but sometimes it's tricky. The PHP fgetcsv function has been more convenient when I have had more exotic examples. If the CSV is simple, awk remains a very good tool.

if the csv is RFC-4180 then it can handle it[0]. the only caveat is that you can't disable FS="" correctly. but a gawk -i ./csv.awk -e '{print $5}' would work on most csv files I've tried.

https://raw.githubusercontent.com/Nomarian/Awk-Batteries/mas...

Re: Awk: The Power and Promise of a 40-Year-Old Language

#88
post #85
post #83

Earlier quoted context omitted.

If you’re using DamnSmallLinux etc I’d imagine you can package your own awk quite easily! Perl would require a lot more packages. But all you need to do is copy a couple binaries right?

Haven't used these distros since a decade or so ago. Not sure why I'd have to package awk. Busybox's is probably sufficient for most uses, if the need ever arised, which I don't think it normally does when using these distros.

Agreed. Not having enough space for awk would be daaaaamn small indeed.

Re: Awk: The Power and Promise of a 40-Year-Old Language

#89

Learning awk is actually pretty simple. For years I just used the '{print $2}' version to extract fields, but after reading some short book I felt pretty confident of having understood the basics. Sadly I don't remember which book it was, but this page looks like a good start: https://ferd.ca/awk-in-20-minutes.html

Likely the one by A, W, and K. https://news.ycombinator.com/item?id=13451454

Yes, this looks like it. Thanks :-)

Re: Awk: The Power and Promise of a 40-Year-Old Language

#90
post #67

Earlier quoted context omitted.

I'm curious what linux distros don't have either some version of perl or python. I like awk, mind, but this is not necessarily (IME) a good argument for it.

The POSIX specification includes awk, but not perl or python. The world of UNIX and UNIX-likes is larger than just Linux distributions. Depending on the utility you plan on building and the platforms you expect it to run on, it may be wiser to reach for awk than other PLs.

Modern BSDs, macOS, and Solaris certainly have Perl and Python. (iOS and Android don't, but they don't have awk either.) What other Unixes are you thinking of? AIX, HP/UX, IRIX, UnixWare, etc. should be considered retrocomputing at this point and not relevant to modern compatibility discussions.

Linux distros based on busybox, as mentioned elsewhere in this thread, are a more compelling reason for considering awk than considerations involving other Unixes.

Post reply on HN