the core is here (https://github.com/lhoursquentin/sed-bin/blob/master/par.sed), and it's 600 lines of beautifully commented sed
Show HN: Sed to C translator written in sed
11–15 of 15 posts
Re: Show HN: Sed to C translator written in sed
#12Re: Show HN: Sed to C translator written in sed
#13Now one for Awk and Python please :)
Re: Show HN: Sed to C translator written in sed
#14Nice! In the why part you speculatively mention better speed. Do you have any concrete benchmark results? If fast, the tool would be very useful for my work where I run an anonimization sed script with hundreds of transformations on millions of lines that takes hours to run. But even if it is not fast, this is a fun project.
If you specify many replacement rules in sed, it will run in O(num_replacements * num_lines). You should be able to use a state machine to do it in O(num_lines), so I google a bit and found this amazing gem: https://unix.stackexchange.com/a/137932
tl;dr: it uses lex to create a custom C program that does "just what you need", compiles it, and runs it on your input. The whole thing wrapped in a bash function. Bonus: it's POSIX compliant.
Re: Show HN: Sed to C translator written in sed
#15Now one for Awk and Python please :)
There's already an awk-to-C compiler [1], even if it seems to be unmaintained. Python has a couple of them, more or less constrained, including Nuitka [2]. [1] http://awka.sourceforge.net/index.html [2] https://github.com/Nuitka/Nuitka