sd
sd copied to clipboard
[Feature Request] Flag to specify file with replacements
replacements.txt:
value replacement
test TEST
sd --replacements replacements.txt file.txt
@ad-si this looks far more suited to shell scripting, like some xargs oneliner.
I personally dislike xargs, so out of personal curiosity I stumbled upon rargs
. Here's what a solution for your case can look like:
rargs -d ' ' sd '{1}' '{2}' file.txt < replacements.txt
Well, that's a quite a one liner. 😅 I'd argue it's way too complicated. Specifying a list of replacements via a file is such a fundamental task I think it should have first class support, but maybe that's just me…?
Specifying a list of replacements via a file is such a fundamental task I think it should have first class support, but maybe that's just me…?
I'm struggling to come up with a workflow to justify this. The only reason I could come up with was to reuse common replacements, but that sounds better served by having the replacement files be scripts or shell functions instead
Also if you're fine with having the find and replace parts in two separate files then the one liner becomes a lot simpler using subprocesses