Is anyone using awk?

Studying and awk came up.

Spent about an hour and I see some useful commands that extend past what “cut” can do. But really when dealing with printf() format statements is anyone using awk scripts for this?

Or is everyone just using their familiar scripting language. I’d reach for Python for the problems being presented as useful for awk.

AMillionNames,

awk is supposed to be simpler. If it isn’t, just use your favorite scripting language. It comes from a period of time when a lot of the scripting languages weren’t as easy to use or readily available.

UNWILLING_PARTICIPANT,

I use awk a good bit. Not as much as when I was doing data work, though. It’s better than cut at splitting on whitespace in many contexts. Lots of other nice uses like variable scope, regex, and summing

WalrusByte,
@WalrusByte@lemmy.world avatar

Sometimes I copy and paste an awk command from online, but I can never remember how to write it myself

cybersandwich,

I’m convinced no one actually knows how to write awk. It’s all copy and pasted from the web.

caseyweederman,

I am very, very slowly chiseling it into my long-term memory. I feel like Rincwind.

WindowsEnjoyer,

Best use-case of AWK is that you can avoid using grep for picking a Nth word in specific line. I tend to ask GPT4 to write one-liner for me. Works super great.

jxk,

Awk has the advantage over Perl/Python/etc. that it’s standardized by POSIX. Therefore you can rely on it on all operating systems. It’s pretty much the only advanced scripting language available that is POSIX – the alternative would be some heavy shell scripting or almost-unreadable sed.

d3Xt3r,

Therefore you can rely on it on all operating systems.

… all except that one OS which we don’t like to talk about but annoyingly remains the most popular consumer OS. :P

yetAnotherUser,

Android?

Decker108,

I think I’ve used it once in 15 years or so. It’s typically easier to go with bash or Python.

j4k3,
@j4k3@lemmy.world avatar

With embedded like OpenWRT on a router where you only have busybox/ash shell, awk is your primary expansions tool.

WaLLy3K, (edited )

awk is pretty damn solid. When I was completely rewriting the gravity.sh script from Pi-hole about six years back, it was easily the fastest for parsing and uniquely sorting content from files with a couple million lines. It made things much more usable on Raspberry Pi Zero hardware, since changing to another language like Python was out of the question.

wuphysics87,

I use sed a lot

bizdelnick, (edited )

Yes, but for a very specific case. I used to write highly portable scripts that could be executed in different environments (various linux distros, including minimal containers, freebsd and even solaris 10). I couldn’t use bash, perl, python and even gawk. Only POSIX shell (I always tested my scripts with dash and ksh93, for solaris 10 compatibility - with its jsh), portable awk (tested with original-awk, gawk and mawk) and portable sed (better forget it if you need to support solaris).

Before that I didn’t understand why should I need awk if I know perl. And awk really sucks. Once I had to replace a perl one-liner with an awk script of ~30 lines for portability.

P.S. I never use awk just for print $1 as many do. It’s an overkill.

bionicjoey,

P.S. I never use awk just for print $1 as many do. It’s an overkill.

cut is better for this use-case IMO. Awk is good for when cut won’t cut it.

picandocodigo,
@picandocodigo@lemmy.world avatar

I learned awk when I was studying and I still use it every now and then. It’s one of those tools that come in really handy at times. I work in Ruby, but there’s still times when scripting or just wanting to process some text when I end up using awk because it makes sense.

upt,

No, but I heavily use perl still… I feel like you can’t really call yourself a Linux person without knowing perl and python both. Knowing awk can’t hurt though.

sping,

Really? I disliked Perl for 3 decades on unix and Linux and I’ve never felt like I have been held back by not knowing or using it. I don’t remember the last time I saw a Perl script, let alone needed to understand one.

SpaceNoodle,

I haven’t found a use for awk that couldn’t be accomplished with bash builtins or other common commands.

neidu2,

Every day. piping srdout to a combination of awk and sed makes shell operations a lot easier. A lot of my earlier perl hacks have now been replaced by a combination of awk, sed, and xargs

starman,
@starman@programming.dev avatar

No, I don’t need it because of jc and nushell

  • All
  • Subscribed
  • Moderated
  • Favorites
  • linux@lemmy.ml
  • localhost
  • All magazines
  • Loading…
    Loading the web debug toolbar…
    Attempt #