9 votes

Topic deleted by author

3 comments

  1. [3]
    acdw
    Link
    I love AWK so much. I'm using it to author my website, I write little scripts in it all the time, and I think I'm going to try to write a Gemini server in AWK. It and shell are my go-tos, as a...

    I love AWK so much. I'm using it to author my website, I write little scripts in it all the time, and I think I'm going to try to write a Gemini server in AWK. It and shell are my go-tos, as a hobbyist. I don't have to worry about virtualenvs or GOPATH or any of that.

    3 votes
    1. [2]
      Phi11ipus
      Link Parent
      AWK is a language which I've always wanted to learn but never have been able to (the best I'm able to do without Googling is just printing the nth word in a line). Do you know of a good way to...

      AWK is a language which I've always wanted to learn but never have been able to (the best I'm able to do without Googling is just printing the nth word in a line). Do you know of a good way to learn it?

      4 votes
      1. acdw
        (edited )
        Link Parent
        Gawk's user manual is actually quite good, but the POSIX manual for awk is also quite good. The biggest thing to know is that AWK scans input by records (default: lines) and splits them up by...

        Gawk's user manual is actually quite good, but the POSIX manual for awk is also quite good. The biggest thing to know is that AWK scans input by records (default: lines) and splits them up by fields (default: whitespace-separated words) and does stuff with them. An awk script is a list of pattern-action blocks, like this:

        /moe/ { printf "MOE! "; }
        { print; }
        

        For every input record, awk tests each pattern for truthiness (which can be any expression; the /.../ part by itself is short for $0 ~ /.../), and if true, performs the related action. So for the above (stupid) example, awk will print every line, prepending lines containing the string "moe" with "MOE! ".

        Where it gets interesting is in the control-flow keywords, like next and getline and the standard if, while, for, as well as the supplied functions. I learned a lot from just reading this markdown-to-html converter too.

        EDIT: There's also this, which I haven't read much of but it looks really good.

        2 votes