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.

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.

starman,
@starman@programming.dev avatar

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

allywilson,

I don’t tend to use awk in scripts as I do tend to do them in Python, but I do use awk on almost daily basis in one-liners.

Probably the most common thing for me is so I can read a config file without annoying comments and big line spaces.

grep -v “^#” krb5.conf | awk NF

eestileib,

Perl kinda killed awk and sed.

Then python kinda killed perl.

AnUnusualRelic,
@AnUnusualRelic@lemmy.world avatar

I used awk until perl, then there was no going back.

hersh,

All the time. Not always by choice!

A lot of my work involves writing scripts for systems I do not control, using as light a touch as is realistically possible. I know for a fact Python is NOT installed on many of my targets, and it doesn’t make sense to push out a whole Python environment of my own for something as trivial as string manipulation.

awk is super powerful, but IMHO not powerful enough to justify its complexity, relative to other languages. If you have the freedom to use Python, then I suggest using that for anything advanced. Python skills will serve you better in a wider variety of use cases.

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.

SpaceNoodle,

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

filister,

Just use awk and when needed ask ChatGPT for the syntax of the command

FaceButt9000,

I use it multiple times a day. I only know basic usage, but it’s super useful as part of an awk/grep/sort/uniq pipeline, basically just extracting a field to work on.

Lydia_K,
@Lydia_K@startrek.website avatar

I use awk all the time, nothing too fancy, but when you need to pull out elements of text it’s usually way easier than using cut.

awk {’ print $3 ‘} will pull the third element based on your IFS variable (internal field separater, default is whitespace)

awk {’ print $NF ‘} gets you the last element, and awk {’ print $(NF-1) '} gets you one element from the last, and so on.

Basic usage but so fast and easy for so many everyday command line things.

FigMcLargeHuge,

You can also add to the output. I use it frequently to pull a list of files, etc, from another file, and then do something like generate another script from that output. This is a weak example, but one I can think of off my head. Not firing up my work laptop to search for better examples until after the holidays. LOL.

awk {‘print "ls -l "$1’}

And then send that to a file that I can then execute.

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.

FigMcLargeHuge,

I use awk constantly at work. Very useful in my opinion, and really powerful if you dig into it.

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