Live data from Hacker News

CLI text processing with GNU awk

learnbyexample.github.io

31–40 of 136 posts

Re: CLI text processing with GNU awk

#31

Awk is fine and dandy but, like wity Sed, I think that it's almost always replaceable with Perl which is way nicer to use, and ubiquitous. Every OS (except Windows) I laid my hands on in the last 15 years has had Perl installed in either its default install or pulled in as a dependency almost immediately (a LOT of stuff depends on Perl in any Unix system). This is, unless you are running on an embedded environment, b…

I was actually surprised to find mktime() in Busybox awk.

The big thing lacking there are the GAWK networking extensions.

Re: CLI text processing with GNU awk

#32
post #19

Earlier quoted context omitted.

> except Windows On Windows, you use PowerShell.

I prefer Cygwin.

I just finished writing a “dumb stuff with containers” internal blog which included:

C:\> type somefile.txt | docker run --rm -i ubuntu awk ‘something’ > output.txt

Re: CLI text processing with GNU awk

#33
confession: plug

I once wrote a diff2html script ported from bash and it was much, much faster (for obvious reasons). And awk makes it much more readable than bash script. And I could learn the language, debug, understand bugs and fix them in a night.

Not sure, if it is idiomatic way to awk, but have to say it is a really nice language.

https://github.com/berry-thawson/diff2html/blob/master/diff2...

Re: CLI text processing with GNU awk

#34
Perhaps my old sysadmin hat is showing through, but I don’t quite see what the advantage of awk is over just writing the same thing in perl. I’ve seen my fair share of horrendous shell scripts from junior sysadmins, and every time I think to myself “the text processing portion would be so much cleaner in Perl”.

Re: CLI text processing with GNU awk

#36

Perhaps my old sysadmin hat is showing through, but I don’t quite see what the advantage of awk is over just writing the same thing in perl. I’ve seen my fair share of horrendous shell scripts from junior sysadmins, and every time I think to myself “the text processing portion would be so much cleaner in Perl”.

Remove perl, have less security issues. Some scanning tools flag it, too. Awk is found in more places, in my experience.

Re: CLI text processing with GNU awk

#37

Awk is fine and dandy but, like wity Sed, I think that it's almost always replaceable with Perl which is way nicer to use, and ubiquitous. Every OS (except Windows) I laid my hands on in the last 15 years has had Perl installed in either its default install or pulled in as a dependency almost immediately (a LOT of stuff depends on Perl in any Unix system). This is, unless you are running on an embedded environment, b…

I have a good story about this: My first time really working with a great scientist, we were taking genetic papers and making them code for improving analysis. I spent two days writing a perl script before I finally got frustrated enough to ask for help.

The first question he asked was "Did you email the author(s)?" I said I hadn't and didn't want to bother this seemingly very important scientist. He told me nonsense, that most of them don't mind responding but he warned me to be terse and to the point. I emailed the gentleman and told him what I was doing and my issues, and asked him for some guidance. He sent me back a one line awk-script that did everything all that perl was failing to do!

Of course all that proves is I'm horrible at perl, but it was an important moment in my life that showed me that even very smart and important people are still just people, and that just asking is often a great way to learn new things yourself, and that sometimes you just need to step back and reconsider what tools you are using. I am forever grateful that an awesome geneticist who needed help bootstrapping tech infra took the time to teach me, a greybeard sysadmin type, practical, reproducible science, from paper to implimentation. I learned a lot but the biggest downside is, after being heavily surrounded by scientists in the workplace in most jobs since then, I find companies without that difficult to work for.

Re: CLI text processing with GNU awk

#38
Of possible interest - instead of making a whole new programming language like awk, you can also just systematize generating code for an existing one with a command-line harness.

This can even stay terse & keep a fairly fast edit-test turnaround in a fully statically typed language like Nim: https://github.com/c-blake/bu/blob/main/doc/rp.md

Re: CLI text processing with GNU awk

#39
A few years back I decided to just get as capable as I could with jq, which is fast and functional enough to cover 99% of awk/sed use cases, plus cases you'd never want to touch with awk/sed.

No regrets!

Re: CLI text processing with GNU awk

#40

Perhaps my old sysadmin hat is showing through, but I don’t quite see what the advantage of awk is over just writing the same thing in perl. I’ve seen my fair share of horrendous shell scripts from junior sysadmins, and every time I think to myself “the text processing portion would be so much cleaner in Perl”.

awk is more intuitive for sure, for a regular javascript coder
Post reply on HN