Allow backup of input file
-b flag, which creates a inputfile.bak backup before replacing.
It will be great. But I think -o output flag will be more beneficial to create new file along with a choice to rename it as well. i.e.
❯ cat url.txt | sd -s 'google.com' 'google.test' -o url2.txt
Should output url2.txt with replaced string. But at the same time, it will easily be achieved via stdout
❯ cat url.txt | sd -s 'google.com' 'google.test' > url2.txt
But I agree what @whitfin has said https://github.com/chmln/sd/issues/1#issue-394260751
I believe backing up files before replacing them is an edge case for the majority of people. If someone is worried about making the wrong replacements, is easy enough to just use pipes and create a new file instead. e.g. sd abc def < important_file.txt > important_file.new.txt
I disagree about it being "easy enough" to use pipes instead, especially because
- your example doesn't even accomplish the desired behavior here; the new content should be in the old filename, and the original content should be in the new filename. The way you have it requires extra work afterward to get to the final state, whereas the desired behavior only requires paying any attention to the backup file if something goes wrong/surprising.
- if you want to do this on a huge tree of globbed files, you'll have to make a loop that carefully manages each placement, and this increases the probability of user error by a lot
Thanks for the great project, btw!