• dontsayaword@piefed.social
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    20 hours ago

    I usually use something like awk ‘{print $2}’ to get a bit of some output

    Ex: list processes, grep for the line I want, then awk out the chunk I want from that line (the pid):

    ps aux | grep myprogram | awk ‘{print $2}’

    • hallettj@leminal.space
      link
      fedilink
      English
      arrow-up
      4
      ·
      20 hours ago

      That’s the only think I know how to do with awk, and I reach for it a lot! cut is purpose-built for that function, and is supposedly easier to understand; but it doesn’t seem to just work like awk does.

      • Victor@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        18 hours ago

        I think cut is a little bit finicky because two consecutive occurrences of the cell delimiter counts, and gives an empty cell when selecting the index between them.

        choose is a bit better at this from what I remember, which is like the modern cut, I believe, of course written in Rust.

        Otherwise Nushell excels at this sort of thing, although I don’t really use it.

        • hallettj@leminal.space
          link
          fedilink
          English
          arrow-up
          2
          ·
          17 hours ago

          Oh, I hadn’t heard about choose!

          I have been using Nushell, and you’re right, it is great at parsing input. Commands like detect columns and parse are very nice, and have been supplanting awk for me.