Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow backup of input file #4

Open
ghost opened this issue Dec 27, 2018 · 3 comments
Open

Allow backup of input file #4

ghost opened this issue Dec 27, 2018 · 3 comments
Labels
M-needs triage Meta: Maintainer label me!

Comments

@ghost
Copy link

ghost commented Dec 27, 2018

-b flag, which creates a inputfile.bak backup before replacing.

@rahilwazir
Copy link

rahilwazir commented Dec 28, 2018

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 #1 (comment)

@chmln
Copy link
Owner

chmln commented Jun 18, 2019

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

@AndydeCleyre
Copy link

I disagree about it being "easy enough" to use pipes instead, especially because

  1. 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.
  2. 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!

@CosmicHorrorDev CosmicHorrorDev added the M-needs triage Meta: Maintainer label me! label May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-needs triage Meta: Maintainer label me!
Projects
None yet
Development

No branches or pull requests

4 participants