• Lauchmelder@feddit.org
    link
    fedilink
    arrow-up
    54
    arrow-down
    1
    ·
    1 month ago

    Why spend 30 seconds manually editing some text when you can spend 30 minutes clobbering together a pipeline involving awk, sed and jq

      • Tangent5280@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        1 month ago

        The important part is to learn the limits of any tool. Nowadays I no longer use jq for any long or complicated tasking. Filter and view data? jq is fine. Anything more and I just cook up a python script.

          • Tangent5280@lemmy.world
            link
            fedilink
            arrow-up
            4
            ·
            1 month ago

            How do you get complex data structures to work? I was alienated from scripting on zsh because I wanted something like a dict and realised I would have to write my own implementation. Is there a work around for that?

            • tal@lemmy.today
              link
              fedilink
              English
              arrow-up
              6
              ·
              edit-2
              1 month ago

              I mean, there’s a point in data structure complexity where it’s useful to use Python.

              But as to dicts, sure. You’re looking for zsh’s “associative array”. Bash has it too.

              zsh

              $ typeset -A mydict
              $ mydict[foo]=bar 
              $ echo $mydict[foo]
              bar
              $
              

              bash

              $ typeset -A mydict
              $ mydict[foo]=bar
              $ echo ${mydict[foo]}
              bar
              $
              
              • Tangent5280@lemmy.world
                link
                fedilink
                arrow-up
                4
                ·
                1 month ago

                This will do nicely - I had several workflows where I’d hit an API and get a massive super nested JSON as output; I’d use jq to get the specific data from the whole thing and do a bunch of stuff on this filtered data. I pretty much resigned to using python because I’d have successively complicated requirements and looking up how to do each new thing was slowing me down massively.

  • DreamButt@lemmy.world
    link
    fedilink
    English
    arrow-up
    17
    ·
    1 month ago

    In all my years I’ve only used more than that a handful of times. Just don’t need it really

    Now jq on the other hand…

  • CubitOom@infosec.pub
    link
    fedilink
    English
    arrow-up
    17
    arrow-down
    1
    ·
    edit-2
    1 month ago

    I’ve become a person that uses awk instead of grep, sed, cut, head, tail, cat, perl, or bashisms

  • otacon239@lemmy.world
    link
    fedilink
    arrow-up
    15
    ·
    edit-2
    1 month ago

    I used awk for the first time today to find all the MD5 sums that matched an old file I had to get rid of. Still have no idea what awk was needed for. 😅 All my programming skill is in Python. Linux syntax is a weak point of mine.

    • Ephera@lemmy.ml
      link
      fedilink
      English
      arrow-up
      6
      ·
      1 month ago

      Probably the very same thing that the post talks about, which is extracting the first word of a line of text.

      The output of md5sum looks like this:

      > md5sum test.txt
      a3cca2b2aa1e3b5b3b5aad99a8529074 test.txt
      

      So, it lists the checksum and then the file name, but you wanted just the checksum.

    • bulwark@lemmy.world
      link
      fedilink
      English
      arrow-up
      6
      ·
      1 month ago

      I remember when I first stumbled across this manual I was trying to look up a quick awk command and wound up reading the whole thing. It’s really one of the better GNU manuals.

  • pelya@lemmy.world
    link
    fedilink
    arrow-up
    9
    arrow-down
    2
    ·
    1 month ago

    Everything you do with awk, you can do with python, and it will also be readable.

  • Doomsider@lemmy.world
    link
    fedilink
    arrow-up
    6
    ·
    1 month ago

    My five thousand line bash script can do things that one hundred thousand lines of code could not do.

    On the brightside, at least script monkeys can now look down on vibe coders.

  • KSP Atlas@sopuli.xyz
    link
    fedilink
    arrow-up
    2
    ·
    1 month ago

    I think the most I’ve done with awk is write a battery monitor applet with it, it involved parsing data from /sys and making choices based on it so I decided it was a decent choice