Live data from Hacker News

Show HN: Sed to C translator written in sed

github.com

11–15 of 15 posts

Re: Show HN: Sed to C translator written in sed

#13
post #7

Now 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

Re: Show HN: Sed to C translator written in sed

#14

Nice! 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.

Not the author, but I had a similar problem.

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

#15
post #13
post #7

Now 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

I mean awk-to-Python transcompiler, it would be useful for datascience. I wonder if it's possible to use awka to create such thing.
Post reply on HN