HNHacker News
TopNewBestAskShowJobs

jlp__inf

3 karma · joined June 8, 2024

j.larget-piet@proton.me
submissionscomments
jlp__inf··on Sed, a powerfull mini-language from the 70s
thanks, i published an article draft about SAM inspired by your examples (referencing sources / this comment section)

Do not hesitate to pin point improvements.

jlp__inf··on Sed, a powerfull mini-language from the 70s
and yess, g/PATTERN/ and /v/PATTERN/ are supzr powerful, creating branch conditions based on wether or not they (do not)match a PATTERN.

based on what you wrote:

i just add trailing \n normalization at the end

, x/(.+\n)+|\n+/ { g/./ x/\n/ c/ / v/./ c/\n/ } $ a/\n/ , x/\n+$/ c/\n/ w file_out.txt q

jlp__inf··on Sed, a powerfull mini-language from the 70s
That's a fair analogy, i am taking the feedbacks into account.
jlp__inf··on Sed, a powerfull mini-language from the 70s
Also, i managed to, i think simplify the second example to: 1,$-2 x/./ { a/->/ /./ t . } 1,$-2 { p } q

Which taught me a lot, because at first, i did not understand why we would stop at last line - 2 ($ - 2), but in fact yeah last line is the very last "\n", that is why we stop at $ - 2 to not do E->weird.

I'm starting to truly love sam

jlp__inf··on Sed, a powerfull mini-language from the 70s
Thanks for those complementary informations.

Also, while i'm learning it, maybe that the sam traduction for the first file would be simpler, like:

,x/\n +/ c/ /

jlp__inf··on Sed, a powerfull mini-language from the 70s
Thanks for sharing this, I’m learning a lot from it.

So if I understand correctly, it’s selection-based, right? You first select a region, and then you can apply further selections inside it?

So you kind of build nested selections to match exactly what you want (almost like a conditional tree).

And then you apply operations on the current selection

For example substitution with something like c/PATTERN/, is that correct?

jlp__inf··on Sed, a powerfull mini-language from the 70s
Yup, notably the famous %s/PATTERN1/PATTERN2/g, which I suppose comes from sed
jlp__inf··on Sed, a powerfull mini-language from the 70s
Ha, I went the Python → AWK → sed route, just for the sake of learning what was behind those chamanics expressions. Glad I could bring back those memories!
jlp__inf··on Sed, a powerfull mini-language from the 70s
Yep, interesting, do you remember the initial text structure and operatins you would perform on it ?
jlp__inf··on Sed, a powerfull mini-language from the 70s
Hi, I'm the author of the article, and sorry if it felt overly LLM-generated.

To clarify: I did spend quite a bit of time diving into `sed` myself (experiments, tests, etc.) and wrote an initial draft in French.

I then used ChatGPT to help me structure and refine the article in English to reach more people. But the core ideas and understanding come from my own exploration.

That said, I understand the concern, and for future articles I'll try to rely less on that kind of tooling for structure.

Happy to clarify or go deeper on any part of the article if needed.