sed is more than search and replace

Поділитися
Вставка
  • Опубліковано 13 гру 2024

КОМЕНТАРІ • 47

  • @feliperezxd
    @feliperezxd 2 місяці тому +10

    I always felt a bit overwhelmed by the sed man page and never got around to reading and fully understanding it, now I'm sure I will, thanks for this great video.

    • @cacharle
      @cacharle  2 місяці тому +1

      I'm glad it helped you

  • @igstan
    @igstan 2 місяці тому +25

    I'm pretty sure the next command you'll cover will be "awk", but you should definitely do a video on "join". It's one of my favorite commands and quite underrated in my opinion. For those not familiar with it, it lets you do SQL-like joins on text files (and/or stdin).

    • @cacharle
      @cacharle  2 місяці тому +10

      We'll see for the awk video
      I'll definitely look into join, thanks for the recommendation

    • @potatoonastick2239
      @potatoonastick2239 2 місяці тому +1

      Thanks for the tip brother! This seems very usefull

  • @mprokop6
    @mprokop6 2 місяці тому +2

    how did you customize your cat output?

    • @cacharle
      @cacharle  2 місяці тому

      It's bat a cat rewrite: github.com/sharkdp/bat

  • @ericfrazer4736
    @ericfrazer4736 2 місяці тому +8

    thanks for sharing! do `awk` next, the real 'swiss army knife' :)

    • @DenzukoDomo
      @DenzukoDomo 2 місяці тому

      sed := swiss army knife, awk := the real 'swiss army knife', perl the swiss army knife of swiss army knifes

  • @GoldoEb
    @GoldoEb 2 місяці тому +1

    Sed is a pretty powerful tool with a pretty obscure syntax in non-trivial use cases.

    • @cacharle
      @cacharle  2 місяці тому

      Indeed, you have to use it carefully if someone else is going to read your code but if you're making some script for your own system that isn't a problem

  • @AvanaVana
    @AvanaVana 2 місяці тому

    Great video. Love sed.

  • @esra_erimez
    @esra_erimez 2 місяці тому +1

    Great video. Fun fact: Lee McMahon wrote the original sed at Bell Labs

    • @cacharle
      @cacharle  2 місяці тому +3

      Thanks, I've never heard of that guy. From his wikipedia page I see he wrote early unix utilities like sed and he's looking like the coolest computer guy in the galaxy with his sunglasses. Anything else I should know?

    • @borisdorofeev5602
      @borisdorofeev5602 2 місяці тому +3

      Lol what can we not thank Bell Labs for? It's like the real life Justice League of smart people with several generations.

  • @arisweedler4703
    @arisweedler4703 2 місяці тому

    Awesome content!! I use vim a ton and know many of the ed-style commands, but have never used sed because I’ve gotten good at awk. I’ve always wanted to know send a bit better, and this video was great for that. I have never understood the “pattern command” as clearly - I got confused with “s/pat/repl/flag” not fitting this - but really “s” is just a special function and doesn’t obey these rules. Or maybe you can make this command apply to a range and implicitly it is the whole file. Anyway - would love to see more advanced sed!

    • @cacharle
      @cacharle  2 місяці тому +1

      The s command is definitely the most complex one but it does obey the same pattern rules as the other commands. You can still sed `/pattern/ s/foo/bar/` if you want.

  • @arman2339
    @arman2339 2 місяці тому +1

    Nice.
    It would have been badass if near the end, you cleaned your file using sed!

    • @cacharle
      @cacharle  2 місяці тому

      It would have been cool idd..

  • @phyphor
    @phyphor 2 місяці тому +2

    My understanding of the "g" is that it means "greedy" rather than "global".

    • @cacharle
      @cacharle  2 місяці тому +1

      man 1p sed says otherwise
      g Globally substitute for all non-overlapping instances of the
      BRE rather than just the first one. If both g and n are spec‐
      ified, the results are unspecified.

    • @phyphor
      @phyphor 2 місяці тому +4

      @@cacharle you can prove anything with facts!
      More seriously, thank you for the correction!

  • @MartialBoniou
    @MartialBoniou 2 місяці тому +1

    You should inform the newcomers that it's GNU sed, not sed. Thanks for the video, btw.

    • @cacharle
      @cacharle  2 місяці тому +2

      I do specify when I use GNU extension (like -E at 5:45 or -i at 13:05) and I try to mention the GNU specific things in most of my videos. Altho 99% of people don't use alpine linux or freebsd so this is definitely not the most important thing to mention

    • @brakenium436
      @brakenium436 2 місяці тому +1

      ​@@cacharleit is rather important if you want scripts to run on MacOS. It's a fairly big market

    • @VincentLAnderson
      @VincentLAnderson 2 місяці тому

      @@cacharle yes, please place greater ephasis on bsd and posix compliant/strict posix, as these are not only more adopted do to mac, but because freebsd, openbsd, netbsd, and dragonflybsd have fewer adopters relative to linux from the lack of an intermediary level of content, either too basic without bigger picture or presumes you are already fairly proficient, the handbooks and man pages help but content creators in actually using the aforementioned help catch blind spots.

    • @cacharle
      @cacharle  2 місяці тому

      @@brakenium436 that's true but as I said in the reply above, I did mention when I use GNU specific thing and I don't want to ramble about different OSes for too long as it would take too much space in a sed focused video

    • @cacharle
      @cacharle  2 місяці тому +1

      @@VincentLAnderson cmon, I mention it 2 times already. Do you really think a sed tutorial where I spend half of my time in how the different implementation work would be interesting?
      Not saying it's not an issue, just that it's always a thing taken out of proportion. If you're making scripts to be portable across so many OSes, you're probably advanced enough to look the relevant resources.

  • @Naceur-r1g
    @Naceur-r1g 2 місяці тому +1

    Where to learn this

    • @cacharle
      @cacharle  2 місяці тому

      RTFM 😄 (in this case man 1p sed)

  • @nejathakan5521
    @nejathakan5521 2 місяці тому

  • @rodelias9378
    @rodelias9378 2 місяці тому +1

    Great video! Thank you! Maybe you could do some vídeos about fish shell

    • @cacharle
      @cacharle  2 місяці тому +1

      Three steps ahead of you! ua-cam.com/video/CiIT-dEDlDM/v-deo.html

  • @aceJacek
    @aceJacek 2 місяці тому +1

    what this cat command is? some code of yours? it does not look like regular cat. great vid, btw.

    • @yassinedownpourz
      @yassinedownpourz 2 місяці тому +1

      It’s bat

    • @cacharle
      @cacharle  2 місяці тому +5

      It's bat, a more modern version of cat: github.com/sharkdp/bat

  • @MeriaDuck
    @MeriaDuck 2 місяці тому

    My best friend and I had a bet whether he could prove sed is Turing complete before a certain date. He succeeded by creating a Turing machine simulator using the multiline feature. He failed because he started two days after the deadline 😂

    • @cacharle
      @cacharle  2 місяці тому

      ahahah that's awesome! I'd love to take a look at the project if you have a link

    • @MeriaDuck
      @MeriaDuck 2 місяці тому

      @@cacharle this was in 1999, don't know if he still has it

  • @klwq
    @klwq 2 місяці тому +1

    French accent ?

    • @cacharle
      @cacharle  2 місяці тому +1

      ok, i'm making a bot that automatically responds to all the french accent comments, this is the 100th time i see this

    • @klwq
      @klwq 2 місяці тому

      😂

  • @MooImABunny
    @MooImABunny 2 місяці тому +2

    yes it is, sed:
    Search
    End
    Dreplace

    • @cacharle
      @cacharle  2 місяці тому

      Lol, I think it stands for Stream ed maybe 🤔