3 ms·
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/
by jlp__inf 6mo ago
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 6mo agoAlso, 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 6mo agoand 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
- piekvorst 6mo agoYeah, sam is not universal, but it can solve complex tasks more simply by just running it a few times. The final example already normalizes \n (v/./ c/\n/) in a single pass, but we can make it even simpler by just writing: , x/(.+\n)+/ .,+#0-#1 x/\n/ c/ / , x/\n+/ c/\n/ (I haven’t tested it.) I’m glad that sam worked out for you. You can learn more from [1] and [2]. If you need any help, you’re always welcome to ask me. [1]: https://ratfactor.com/papers/sam_tut.pdf https://ratfactor.com/papers/sam_tut.pdf [2]: https://9p.io/sources/contrib/steve/other-docs/struct-regex.pdf https://9p.io/sources/contrib/steve/other-docs/struct-regex....
- jlp__inf 6mo agothanks, i published an article draft about SAM inspired by your examples (referencing sources / this comment section) Do not hesitate to pin point improvements.