Discussion
Sed, a powerfull mini-language from the 70s
supriyo-biswas: This would have been a good article if the author actually took the time to write out the article themselves, perhaps in their native language, rather than using a LLM to write it.
evanjrowley: For a while my home had a Raspberry Pi 2B running FreeBSD 10 acting as a router-on-a-stick. When I lost SSH connectivity to it, I would instead use GNU screen as with a serial cable. For whatever reason, I could never get "full screen" TUI apps like vi and nano to display properly. To edit files (like pf.conf for firewall rules), I had to use sed to edit lines of the file. It was an interesting learning experience and perhaps a glimpse of how things used to be with green screen terminals. Shortly thereafter I switched over to a Beaglebone Green with OpenBSD 5 and never needed that workaround again.
jasonpeacock: Long ago, I bought the O'Reilly "Sed & Awk" book with plans to become a true unix guru.Then I realized I already knew Perl (and Perl one-liners), so there it sat unused on the shelf.
piekvorst: I prefer sam [1]. Unlike sed, it's not Turing complete, but far more elegant to my taste. Consider this example from the article: :loop N; s/\n[[:space:]]\+/ /g; t loop; p In sam, the equivalent is: x/(.+\n)*/ x/\n */ c/ / It reads like this: loop over (.+\n)* (paragraphs of non-empty lines), loop over newline followed by spaces, replace with the single space. It's surprisingly close to SQL in its eloquence.Another example: N; h; s/\n/->/g ;p; g; D In sam, a rough equivalent would be { 1,$-2 x/./ { a/->/ /./ t . } $-1 d } Again, it's readable from the top to the bottom: from the first line to the second one from the end, loop over each symbol, put "->" after it and copy the next symbol next to it; delete the first line from the end.Let's see how far can we get. Another example: N; h; s/\n/->/g; p; G; D In sam, a rough equivalent would be: { d 1,$-2 x/./ { 1,/./ x/.|\n/ { g/./ t $ g/\n/ $ c/->/ } $ c/\n/ } } It gives the same output, except for extra "->" at the end of each line.The final example from the post is too long to paste it here. Here's just the sam equivalent for it: x/(.+\n)+|\n+/ { g/./ x/\n/ c/ / v/./ c/\n/ } It reads like this: loop over paragraphs of non-empty lines or a sequence of newline characters; if it has any symbol (that is, it's a paragraph), replace each newline symbol with space; if it doesn't have a symbol (that is, a sequence of newline symbols), replace it with a single newline.What I learn from this is that the right concept, however limited (and sam is far from being universal), can be more powerful than pure state machines.(My examples are not the exact same algorithms, since I do not understand (or need) sed concepts.)[1]: https://9p.io/sys/doc/sam/sam.html