What do y’all use awk for really? 20 of using Linux, I’ve never had to use awk. And I’ve done a looot of scripting in my days. Anything from building my own clone of polybar using eww (with loads of scripts underneath), to automated systems for bulk handling of student assignments back at uni when I used to help out with grading and such.
What’s awk good for that other standard utilities can’t do?
I’ve been using Linux for 25 years, awk is a more recent addition to my arsenal, but rapidly becoming more and more useful.
For example, awk is extremely helpful if you want to rearrange columns, do math on columns, essentially do things that would take multiple lines of bash with cut and read.
I used to switch to perl or python if I needed awk. These days I don’t tend to run into it as much. Not sure if that was a good choice. But it’s how I spent the past 25 years.
That’s the only think I know how to do with awk, and I reach for it a lot! cut is purpose-built for that function, and is supposedly easier to understand; but it doesn’t seem to just work like awk does.
I think cut is a little bit finicky because two consecutive occurrences of the cell delimiter counts, and gives an empty cell when selecting the index between them.
choose is a bit better at this from what I remember, which is like the modern cut, I believe, of course written in Rust.
Otherwise Nushell excels at this sort of thing, although I don’t really use it.
I have been using Nushell, and you’re right, it is great at parsing input. Commands like detect columns and parse are very nice, and have been supplanting awk for me.
grep, sed, awk, and find
What do y’all use awk for really? 20 of using Linux, I’ve never had to use awk. And I’ve done a looot of scripting in my days. Anything from building my own clone of polybar using eww (with loads of scripts underneath), to automated systems for bulk handling of student assignments back at uni when I used to help out with grading and such.
What’s awk good for that other standard utilities can’t do?
I use awk instead of cut cause I can remember the syntax better.
ps aux | grep zoom | grep -v grep | awk ‘{print $2}’ | xargs kill -9
I’ve been using Linux for 25 years,
awkis a more recent addition to my arsenal, but rapidly becoming more and more useful.For example,
awkis extremely helpful if you want to rearrange columns, do math on columns, essentially do things that would take multiple lines ofbashwithcutandread.I used to switch to
perlorpythonif I neededawk. These days I don’t tend to run into it as much. Not sure if that was a good choice. But it’s how I spent the past 25 years.That makes sense! I think I’d be running Nushell for this if the scripts didn’t need to be very portable, sounds like a good use case for that.
I usually use something like awk ‘{print $2}’ to get a bit of some output
Ex: list processes, grep for the line I want, then awk out the chunk I want from that line (the pid):
ps aux | grep myprogram | awk ‘{print $2}’
That’s the only think I know how to do with awk, and I reach for it a lot!
cutis purpose-built for that function, and is supposedly easier to understand; but it doesn’t seem to just work like awk does.I think
cutis a little bit finicky because two consecutive occurrences of the cell delimiter counts, and gives an empty cell when selecting the index between them.chooseis a bit better at this from what I remember, which is like the moderncut, I believe, of course written in Rust.Otherwise Nushell excels at this sort of thing, although I don’t really use it.
Oh, I hadn’t heard about
choose!I have been using Nushell, and you’re right, it is great at parsing input. Commands like
detect columnsandparseare very nice, and have been supplanting awk for me.