Settings

Theme

Replace multiple strings, O(1) wrt number of replacements

unix.stackexchange.com

1 points by alphaBetaGamma 5 years ago · 1 comment

Reader

alphaBetaGammaOP 5 years ago

I was using sed to do many replacements (hundreds) in a file and it was starting to be slow, running in O(num_replacemnts). I thought that this can be done with a state machine so the runtime could be independent of the number of replacements.

I googled a bit and found this amazing gem: it uses lex to create a custom C program that does just what you want. Posix compliant. All wrapped up in bash function.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection