Hacker News new | comments | show | ask | jobs | submit login
Awk driven IoT (astier.eu)
181 points by Aissen 189 days ago | hide | past | web | favorite | 35 comments

I'm reminded of two other surprising uses of Awk -- "Awk for AI"[0] and "awk-raycaster"[1]

I really like Awk as a language because it integrates so well with shell pipelines and it is incredibly small, while remaining high-level enough to be practical, which I think this project demonstrates quite well.

[0]: https://web.archive.org/web/20140926113347/http://www.wra1th...

[1]: https://github.com/TheMozg/awk-raycaster

Awk is already well-known in embedded systems, eg. busybox implements a lot of POSIX using awk IMO.

Also, awk syntax is clearly the predecessor of JavaScript. The following is both awk and JavaScript:

    function f(x) {
        my_array[1] = "whatever"
        my_array["a string"] = "something else"
        if (x in my_array) return my_array[x] 
It's all there: the "in" operator, no need for semicolon as statement terminator, the "function" keyword, untypedness, regular expression constants, C-like curly braces, etc.

Yeah Awk and JavaScript have surprisingly similar syntax. But the semantics are very different. Here are some things I found when studying Awk a bit more:

- Awk has no local variables! There is no "var". Believe it or not, people fake locals with unused function parameters.

- Awk has no dict literals like d={}. And no function literals like f = function(x) { return x; }

- Awk dicts can't be nested. You can't have something like: {key1: {key2: 123}} (using JS syntax)

- Awk CAN accept dicts as parameters, but it CAN'T return them. "return d" is invalid.

- Awk can't take functions as parameters OR return them. That is, no higher order functions.

The latter three facts are basically consequences of the fact that Awk has no garbage collection. It has a strict stack discipline and no nested compound data structures.

Yes, and another difference is the use of 1-based string indexes, as opposed to 0-based string indexes in JavaScript. Even though I started with C many years ago (where 0-based string indexes are there for a reason, unlike in Java and JavaScript IMHO), I found 1-based string index semantics to allow much more compact and idiomatic expressions for typical string massaging tasks.

> busybox implements a lot of POSIX using awk

Citation, please?

It looks like busybox implements the 'dos2unix', 'tac', and 'unix2dos' commands as shell scripts that call 'sed'. And there are a couple of awk scripts (e.g. 'scripts/checkhelp.awk') that are used during the busybox build process. But as far as I can tell, all of the actual busybox applets are written in plain C.

I'd love to be wrong on this point, however -- I think that implementing a full POSIX userspace with just /bin/sh and /bin/awk is an awesome idea!

Add in dollar signs before the variables and you very nearly have valid Powershell as well.

>It's all there: the "in" operator, no need for semicolon as statement terminator, the "function" keyword, untypedness, regular expression constants, C-like curly braces, etc

At some point, these polyglots must merge. It makes no sense to have arbitrary particles be the only distinction between languages.

Is there any downside to using JS instead of Awk for one-line shell scripting? Maybe it's time to retire Awk, and use js/Perl/whatever instead for that purpose?

Awk is much faster, and much more consistent in its memory management, and doesn't have some of the things that trip people up in JS (== vs ===, order of operations).

Plus, awk is probably in any *nix system, and probably doesn't need any updates to behave as expected. (And my favourite little thing: awk's executable is tiny.)

Awesome project!

There's a company who developed a cute product around this type of technology. It's a bestselling toy in Germany.


Wow, op here, I had never heard about tonies ! It seems to be exactly the same concept, awesome ! It seems good ideas happen at the same time :-)

> It's a bestselling toy in Germany.

German here; never heard of it, but looks amazing for my daughter. Thanks for mentioning this!

Tape cassettes are a dime a dozen whereas you pay 15€ for a story tonie. Inserting a cassette and pressing play is also not too difficult for a child.

That's true and I was really concerned about that pricing, too. What I like about the Tonie: I need to travel a lot business wise and can use their app to record e.g. sounds of a city, songs I play on my guitar etc. and deliver them to my kids Tonie. Because it's connected to the home WiFi.

My kids love it and highly recommend it. I never heard of it before until last XMAS.

Love it! I worked on a research project where we built a lot of CLIs to pull data form a sensor, send it over a Unix Pipe to a push CLI for a database. It offers some fun flexibility and really fast implementations.


The article mentions mawk which is one of the faster awks I know of. Then there is awka that compiles awk script to C. Do you know of other speed demons apart from these. I think cleaning up the language by removing some of the one-off constructs and making it more regular (npi) could make faster implementations possible. An embeddable/extendable awk that exploits simd and multicore could potentially lift a lot of weight.

I wish awk had more mind share than it does these days.

I've been using AWK for decades, but the NFC avatars are new to me.

Has anyone started a business where you send in some photos, or sit for a sculptor, then they 3D print a set of NFC caricatures for you? I imagine it would be fairly easy to do, especially if the sculpture tutor at your local art school was willing to help with hiring.

Somewhat gratuitous use of awk. It could be bash driven IoT:

   ... | while read -r line; do
   case "$line" in
     *"03 52 c1 1a"*) echo "file1 "; file="file1.mp3" ;;
   if test -n "$file"; then
     mpg321 -q "$file" &

Really cool project. I'm already using mpd on my rpi to play music (controlled with the iPhone mPod app).

Would be cool to let my 3.5yr old boy play some songs he likes... But at his age, I need to think of a more advanced physical controller or remote (any suggestions?)

Amazon Dash is a one-button solution, if he can't press buttons yet you just need to hack it so another action triggers the "button press" event.

But how can he choose different tunes? Hope to find some kind of controller that's fun for him to use.

... and of course he can press a button :)

Have several dash buttons? Like in the article where each figure plays a different tune.

Otherwise you'd have to macgyver a toy with giant buttons, build a Bluetooth device onto it that sends a different signal for each button.

They have like a 4 second latency, which would be tough for a child.

Now really do an inet aware interface with (g)awk: https://www.gnu.org/software/gawk/manual/gawkinet/html_node/.


Please don't submit puns which can be found in other comments already. In general, you should only comment if it brings something new to the discussion.

>In general, you should only comment if it brings something new to the discussion.

This has been said already, so should you be commenting this?

You are right, it would not make sense to reply now. But at the time of my reply, the user account was 44 days old and the comment was at the top of the submission. I presumed the user among other people were not aware of HN guidelines.

My comment was intended to say that just like your comment might be new to them, their comment will be new to many. So there's no need to police them.

Everyone who signs up shouldn't have to look through all the popular comments of the past and then decide if they can comment or not. If it is annoying to you, downvote it. The fact that it was at the top should tell you that it is appreciated by many, so that comment isn't as well known as you might think.

This is awesome!

Why, exactly?

Because it's using a 41 year old language which has ultra low memory requirements, no dependencies and runs like a bandit, on internet of things. (And can be compiled to machine code by using Awka.)

In Bryan Cantrill's (paraphrased) words: "let there be an orgy of AWK one-liners!"

(Or even better, entire applications written in AWK, since the language is perfect for dynamically generating web applications.)

Awk is pretty awesome - certainly one of my first loves. As I often do when it comes up in an HN thread if anyone has the artwork or is willing to scan said artwork of the infamous Bell Labs T-shirt I would be eternally grateful. It emphasizes the one weak point of AWK which is debugging. The shirt shows a gangly bird parachuting out of an airplane and reads "Awk bailing out near line 1"

The original as referenced here - ftp://minnie.tuhs.org/UnixArchive/Documentation/Books/Life_with_Unix.pdf - is no longer available as "The Independent UNIX Bookstore" no longer exists.

To give the parent the benefit of the doubt, I think the point he was making was less "this isn't awesome" and more "explain why you think it's awesome, don't just place your upvote in the form of a comment".

Thank you. I expected that my addition of "exactly" would help, but honestly, my post was rather lazy.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact