Studying and awk came up.

Spent about an hour and I see some useful commands that extend past what “cut” can do. But really when dealing with printf() format statements is anyone using awk scripts for this?

Or is everyone just using their familiar scripting language. I’d reach for Python for the problems being presented as useful for awk.

  • Lydia_K@startrek.website
    link
    fedilink
    English
    arrow-up
    58
    arrow-down
    1
    ·
    11 months ago

    I use awk all the time, nothing too fancy, but when you need to pull out elements of text it’s usually way easier than using cut.

    awk {’ print $3 '} will pull the third element based on your IFS variable (internal field separater, default is whitespace)

    awk {’ print $NF ‘} gets you the last element, and awk {’ print $(NF-1) '} gets you one element from the last, and so on.

    Basic usage but so fast and easy for so many everyday command line things.

    • FigMcLargeHuge
      link
      fedilink
      English
      arrow-up
      14
      arrow-down
      1
      ·
      11 months ago

      You can also add to the output. I use it frequently to pull a list of files, etc, from another file, and then do something like generate another script from that output. This is a weak example, but one I can think of off my head. Not firing up my work laptop to search for better examples until after the holidays. LOL.

      awk {‘print "ls -l "$1’}

      And then send that to a file that I can then execute.