Replace sed for the simplest use cases. https://github.com/xenosoz/denma
It's in quick and dirty MVP state for the personal use. Ping me if you think we need to improve this seriously.
We have three slashes in "s/old/new/command" the perl-style replacement format. That means we need to escape slashes every time we want to use in the old, new and command section. I am tired of it. But I'm lucky enough to have python within my era.
Update: We learn sed is capable of changing its delimiter. See Back to sed section below.
Denma exposes a variable line
for each line.
You can write an expression for the replacement or just update the variable the with statements.
We present three equivalent commands below:
sed 's/a\/very\/old\/and\/long\/path/new\/path/g' -i input.txt
denma.py -i -c "line.replace('a/very/old/and/long/path', 'new/path')" input.txt
denma.py -i -c "import re; line = re.sub('a/very/old/and/long/path', 'new/path', line)" input.txt
After creating this project, we got a feedback from @ehooi. We really appreciate it. We might still stick to sed:
sed 's#a/very/old/and/long/path#new/path#g' -i input.txt
We can also use any character but a backslash or newline as a delimiter. Two references here:
- GNU sed manual: "The '%' may be replaced by any other single character."
- Freebsd sed manual: "Any character other than a backslash or newline can be used instead of a slash ..."
MIT License as per LICENSE.md.
Created by Taihyun Hwang <[email protected]>