• 👍Maximum Derek👍@discuss.tchncs.de
    link
    fedilink
    English
    arrow-up
    56
    ·
    10 天前

    The first language I was fluent in was Perl so PCRE is second nature to me. But then everyone decided they wanted their own regex dialects. And now there’s a PCRE2? Why 2? Stay with 1, you’re good together. What about the kids?

  • mogoh@lemmy.ml
    link
    fedilink
    arrow-up
    48
    ·
    10 天前

    Which one of these commands is correct?

    A: sed -E 's/\b(\w+)\b/echo \1 | rev/g' file.txt
    B: sed 's/\b\w+\b/echo & | rev/ge' file.txt
    C: sed -E 's/(\w+)/$(echo \1 | rev)/g' file.txt
    D: sed 's/\([a-zA-Z]\+\)/\n&\n/g; s/\n\(.*\)\n/\3\2\1/g; s/\n//g' file.txt

    Chatty was so kind to transcribe. May contain errors.

    • alienghic@slrpnk.net
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      20 小时前

      The transcription of D is wrong. It should be:

      sed 's/\([a-zA-Z]\+\)/\n&\n/g; s/\n\(.\)\(.*\)\(.\)\n/\3\2\1/g; s/\n//g' file.txt

      also D is correct, assuming file.txt contains a list of words one per line

    • mogoh@lemmy.ml
      link
      fedilink
      arrow-up
      38
      ·
      10 天前

      Chatty claims the correct answer to be:

      Spoiler

      B

      I tried it my self and I conclude:

      Spoiler

      none is correct.

      • UltraBlack@lemmy.world
        link
        fedilink
        arrow-up
        11
        ·
        10 天前

        Thought so lol

        A: didn’t even try what by does B: Single quotes prevent execution C: there is no way to execute commands afaik so this won’t work either D: that syntax is just wrong afaik

    • Onno (VK6FLAB)@lemmy.radio
      link
      fedilink
      arrow-up
      18
      ·
      edit-2
      10 天前

      Google Lens says:

      Which one of these commands is correct?
      
      A sed -e 's/\b(\w+)\b/echo \1 | rev/g' file.txt
      
      B: sed 's/b\w+\b/echo & | rev/ge' file.txt
      
      Csed -e 's/(\w+)/$(echo \1 | rev)/g' file.txt
      
      D: sed 's/([a-zA-Z]\+\)/\n&\n/g; s/\n\(\)\(.*\)\(\)\n/\3\2\1/g; s/\n//g' file.tx
      

      It’s interesting that Google doesn’t even get all the text. I had to manually extend the selection and that still misses the “t” on the end of answer D, munches C and more alarmingly changes the case for “-E”.

        • morrowind@lemmy.ml
          link
          fedilink
          arrow-up
          12
          ·
          10 天前

          OCR was AI.

          Anyway today’s models are measurably better especially when you go beyond simple text on a clean page.

        • vivendi@programming.dev
          link
          fedilink
          English
          arrow-up
          5
          ·
          10 天前

          Any good OCR model also uses “AI”

          And LLMs are usually really good at detecting text

          Source: Had to OCR a quite a few ancient university papers

    • bus_factor@lemmy.world
      link
      fedilink
      arrow-up
      12
      ·
      10 天前

      I don’t see anything wrong with the capture groups in A and C. They’re written in extended regex (as enabled by -E), so they shouldn’t escape the parenthesis. Am I missing something?

  • ABC123itsEASY@lemmy.world
    link
    fedilink
    arrow-up
    4
    ·
    10 天前

    I some beef with this meme in that there really isn’t a way to simply do this in windows. If anything, it demonstrates the upper level of capability and function using a cli shell. People who are looking for a windows replacement would never need to understand this command or even use a pipe / regex as they were unlikely to have been doing this kind of thing with windows anyway.

      • ABC123itsEASY@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        10 天前

        That’s fair! I’ve always seen this community as an environment for advocating Linux use to Lemmings and much of the time the memes are comparative in nature to other options (ex the current to meme in this community about vendor lock in) so I’m just injecting my own historical view about this community. If it’s not comparative; then why is it really that funny? In that case it just reads like an exam in a CIS final.

          • ABC123itsEASY@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            10 天前

            Right I love that comic! But I think the joke there is the expectation that a unix user would be able to do something as simple as opening a .tar.gz file, something that’s a much more common experience among nix users, but truth is many experienced users would still need to look up the exact syntax (me included). This meme is more like “look at how absurd of a command you can use in bash; can you tell the difference?” I dunno just doesn’t hit the same to me. Appreciate you sharing that xkcd though.

      • ABC123itsEASY@lemmy.world
        link
        fedilink
        arrow-up
        5
        ·
        edit-2
        10 天前

        I could imagine a command like this being used as part of a CI/CD script doing static analysis in a virtualized environment where the build is running in a *nix container. There’s more maintainable options as well (ie easier for an entire team of developers to understand / lower ‘bus factor’).

        Lol someone is so mad about this they’re going around downvoting all my replies. Guess that’s easier than coming up with a thoughtful reply and actually conversing but whatever you do you boo

        • Justin@lemmy.jlh.name
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          10 天前

          Build scripts are often written in bash, yes, but I would say that you should find a utility program, or write your own utility in python, if you’re breaking out sed. It’s very hard to read code like this, no matter the team size.

          There’s probably only 100-300 usages of sed in the entire nixpkgs repo, with over 100,000 packages.

          I definitely agree Linux is easier to maintain and build code on than Windows, but yeah abusing sed is not really an ideal use case 😅