Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost
thanks i hate it

Adbot
ADBOT LOVES YOU

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

rjmccall posted:

i wasn’t aware awk had that kind of math processing at all

as far as i am aware, if you want to do non-integer arithmetic in a shell script, the most portable way by far is to invoke awk with your expression; dc and bc aren't available in nearly as many places as some version of awk

as for why you'd need to do that sort of thing in a shell script,

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

during the pandemic I taught this class that used a bunch of unix primitives to introduce systems primitives to second-year CS majors and I'm convinced my greatest coup was tossing out the original "this is a class on stupid bash tricks and re-implementing first year CS assignments in perl" curriculum to pad the back half of the class with awk

not least because once you see that awk lets you open a socket by opening a pseudofile in /inet/tcp/ you've already motivated discussion on plan9

crazypenguin
Mar 9, 2005
nothing witty here, move along

pseudorandom name posted:

its so you can include the version string in bug reports op

yeah they probably got bit by bugs in bad versions that linux distributions yolo'd in there and never bothered to in any way test, and of course never update either

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Internet Janitor posted:

as for why you'd need to do that sort of thing in a shell script,

I’ve used it to add up elapsed times, or give an average time, IIRC. maybe I just dreamed that

Zlodo
Nov 25, 2006

MononcQc posted:

Awk's variables are hosed up, but the workaround for them is hilarious: if you declare a variable as a function parameter, it won't share a scope with the parent callers; also if you declare a variable as a function parameter and it is not put in by the caller, it's gonna be uninitialized. Therefore, declare your local-scoped variables as function parameters. Here's a snippet from some code I wrote when doing the 2021 advent of code with Awk (up until day 14):

code:
func common(k,arr,    i,c) {
    for (i in arr) { c += arr[i][k]*2-1 }
    return c>=0
}

func cull(k,v,arr,    i) {
    for (i in arr) { if (arr[i][k] != v) { delete arr[i] } }
}

func to_n(arr,    i,j,c) {
    for (i in arr) { for (j in arr[i]) { c=lshift(c,1)+arr[i][j] } }
    return c
}
So these "conventions" you can use of putting a bunch of whitespace between params and local values lets you be a bit more explicit about what is a globally scoped and what is a locally scoped variable.

also I will always mention my tutorial to learn awk in 20 minutes: https://ferd.ca/awk-in-20-minutes.html

Here's a vastly better awk tutorial that takes only 5 seconds:

sudo rm `which awk`

FlapYoJacks
Feb 12, 2009
I use awk and all of its power to exclusively use it in the same way cut is used. :smug:

Visions of Valerie
Jun 18, 2023

Come this autumn, we'll be miles away...

Soricidus posted:

I don’t really understand the need to learn advanced awk stuff when perl is right there out of the box too on most unices (and way more portable), but I respect people who do it anyway

To give a serious answer, it's available but not always installed on Linux. Like, kernel and stuff need it to build, but it's not present on base installs of e.g., Fedora. Minimization people get pissy when it's your package that's dragging in a whole language into the minimal system, even if basically anything the user installs would drag it in.

(And of course perl has the whole "write-only" stigma attached, deservedly or no, while awk doesn't.)

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Zlodo posted:

Here's a vastly better awk tutorial that takes only 5 seconds:

sudo rm `which awk`

shouldnt you use alternatives and xargs to get all of them?

Zlodo
Nov 25, 2006

leper khan posted:

shouldnt you use alternatives and xargs to get all of them?

If awk still unfortunately works just run the command again

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
nobody has ever seriously considered making a package manager for "awk libraries" or "awk frameworks"

with the exception of the usual GNU extensions traps, there's no dependency hell

you just write programs as one file in terms of the functionality awk gives you out of the box

this is an underappreciated virtue

DELETE CASCADE
Oct 25, 2017

i haven't washed my penis since i jerked it to a phtotograph of george w. bush in 2003

FlapYoJacks posted:

I use awk and all of its power to exclusively use it in the same way cut is used. :smug:

awk is better than cut because it collapses multiple spaces into one

neosloth
Sep 5, 2013

Professional Procrastinator
I really love awk for quick text processing tasks. Not having real csv support until 2023 (and I dont think gnu awk has it yet?) sucked but I think I'll use it more now

DELETE CASCADE
Oct 25, 2017

i haven't washed my penis since i jerked it to a phtotograph of george w. bush in 2003
csv support? does it handle quoted newlines?

Zlodo
Nov 25, 2006

Internet Janitor posted:

nobody has ever seriously considered making a package manager for "awk libraries" or "awk frameworks"

with the exception of the usual GNU extensions traps, there's no dependency hell

you just write programs as one file in terms of the functionality awk gives you out of the box

this is an underappreciated virtue

Yes its very easy to toss a small self contained package in the trash

neosloth
Sep 5, 2013

Professional Procrastinator

DELETE CASCADE posted:

csv support? does it handle quoted newlines?

Yeah
https://github.com/onetrueawk/awk?tab=readme-ov-file#csv

DELETE CASCADE
Oct 25, 2017

i haven't washed my penis since i jerked it to a phtotograph of george w. bush in 2003
dope af, wouldn't have expected that from a line-oriented (ok ok record-oriented) tool like awk

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
if I was the maintainer of awk I'd call myself the awkwarden

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



pokeyman posted:

if I was the maintainer of awk I'd call myself the awkwarden

lol

defmacro
Sep 27, 2005
cacio e ping pong
awk is wak

minidracula
Dec 22, 2007

boo woo boo
rawk out with your awk out

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Dijkstracula posted:

not least because once you see that awk lets you open a socket by opening a pseudofile in /inet/tcp/ you've already motivated discussion on plan9

and you would desire that why?

DELETE CASCADE
Oct 25, 2017

i haven't washed my penis since i jerked it to a phtotograph of george w. bush in 2003

eschaton posted:

and you would desire that why?

everything is a file

Bloody
Mar 3, 2013

is awk web scale

redleader
Aug 18, 2005

Engage according to operational parameters

Bloody posted:

is awk web scale

yes, but you'll want to containerize it so it uses consistent versions of the various math libraries it depends on

prisoner of waffles
May 8, 2007

Ah! well a-day! what evil looks
Had I from old and young!
Instead of the cross, the fishmech
About my neck was hung.
hmm. I’m a total sicko for jq and yq. maybe I should learn awk.

minidracula
Dec 22, 2007

boo woo boo

prisoner of waffles posted:

hmm. I’m a total sicko for jq and yq. maybe I should learn awk.
merge them all into new a monstrosity called jaqkwyq (pronounced JACK-quick)

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
if i could change one thing about awk i think i'd make associative arrays first-class values

it would definitely complicate the implementation, though

12 rats tied together
Sep 7, 2006

if you were going to do that you would instead just `python -c`. just learn awk, its good and useful, and will save you from creating the n+1th dumb CLI tool at your organization

minidracula
Dec 22, 2007

boo woo boo

Internet Janitor posted:

if i could change one thing about awk i think i'd make associative arrays first-class values

it would definitely complicate the implementation, though
Someone did!: http://lua.org/

I jest, of course, but I also love Lua, and honestly, after you move past what awk is good at, I want to make the claim that Lua should be your next stop on the complexity train for CLI-style text processing, if just for tables, patterns, and (if necessary) LPeg.

I realize this is a bold take given Perl exists and my invocation of Lua will return us to the debates about 0- versus 1-indexing, but like eternal return, we have closed the circle, the circle of life. Hakuna matata.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
well obviously when i have to do that sort of thing i use lil because, like many people who choose to post in the p-lang thread, i already have my own bespoke scripting language

i was only speaking hypothetically; adding new features to a fork of awk wouldn't result in them being available in all the places awk already is, so it wouldn't confer any benefit over installing your choice of general-purpose scripting language

minidracula
Dec 22, 2007

boo woo boo

Internet Janitor posted:

well obviously when i have to do that sort of thing i use lil because, like many people who choose to post in the p-lang thread, i already have my own bespoke scripting language

i was only speaking hypothetically; adding new features to a fork of awk wouldn't result in them being available in all the places awk already is, so it wouldn't confer any benefit over installing your choice of general-purpose scripting language
Oh, yeah, I know you weren't being serious, and I figured Lil would be your weapon of choice, because of all the same reasons you said. I just wanted to take the opportunity to make the goof-only-ha-ha-but-serious on considering Lua as another text processing plang. This only probably makes sense if you don't already know or have Python or Perl or other suitable language, or don't want to deal with installing those for whatever reason, etc., etc., etc.

In sum: when I get past awk, I reach for Lua, even though I could do things in Python or whatever, because I like Lua for that job, and I think it does it well, despite not really being thought of much in the same class as Perl. Python in some ways has ate the world for now, so of course it could and can do this too.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
i think the programming world would be a much better place if lua had beaten python to the punch with respect to notebooks and scientific computing

lua has some warts, but on the whole it's a tremendously simpler, more coherent, and more flexible language than python

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Torch tried…

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost

Internet Janitor posted:

i think the programming world would be a much better place if lua had beaten python to the punch with respect to notebooks and scientific computing

lua has some warts, but on the whole it's a tremendously simpler, more coherent, and more flexible language than python

the language is never the source of the infinite complexity. if a million scientists wrote poo poo scientist code in lua that would be the nexus of infinite complexity

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
both python itself and the python ecosystem are extremely hairy and heterogenous

if scientists wrote millions of lines of bad lua it would still be less terrible than millions of lines of bad python because lua can get non-dogshit performance without punting everything to c

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost
fortran can also do that and yet its terrible

feedmegin
Jul 30, 2008

BobHoward posted:

there should be no legal or technical barrier to someone else doing a rosetta equivalent on their arm64 system, and i wouldn't be surprised to see it done in windows on qualcomm's upcoming high performance WoA SoCs

Huh, is Windows on ARM still trying to be a thing then? It faceplanted in mobile phones and I didn't think Windows for Internet of Things got anywhere either.

(if it is, well, I write a compiler for fun and it can a) do Windows and b) do ARM so...)

champagne posting
Apr 5, 2006

YOU ARE A BRAIN
IN A BUNKER

BobHoward posted:

there should be no legal or technical barrier to someone else doing a rosetta equivalent on their arm64 system, and i wouldn't be surprised to see it done in windows on qualcomm's upcoming high performance WoA SoCs

I'm kinda surprised microsoft didn't do this for Windows RT or at any point really.

Adbot
ADBOT LOVES YOU

BobHoward
Feb 13, 2012

The only thing white people deserve is a bullet to their empty skull

feedmegin posted:

Huh, is Windows on ARM still trying to be a thing then? It faceplanted in mobile phones and I didn't think Windows for Internet of Things got anywhere either.

(if it is, well, I write a compiler for fun and it can a) do Windows and b) do ARM so...)

this time it's not phones or IoT, it's laptops and tablets and desktops running full windows 11 (not a hamstrung version) with a rosetta equivalent to run x86 software. microsoft's rosetta isn't as good, but i've heard it has made huge strides and is decent, if a bit limited by existing win-on-arm hardware

as to that hardware, it's mostly microsoft with a few surface branded arm tablets and laptops, and even a mac mini like SFF desktop they sell as a dev kit. there's also a few other machines made by oems.

so far it's been very niche since performance in existing non-apple arm SoCs just isn't competitive with x86. qualcomm's looking to change that

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply