-
Notifications
You must be signed in to change notification settings - Fork 142
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
Pass matched string to command #75
Comments
Seems like both sed and sd can do the cmd output thing, but it also seems none of them can handle cmd output and capture groups. :( |
@pvinis: When you say the cmd output thing is possible, do you mean sed or sd can do what I described in my original comment? The equivalent of |
I guess like https://stackoverflow.com/a/17301724/377456. That works for you, right? Using I needed the capture too, so I ended up using perl https://github.com/pvinis/home-dashboard/blob/master/scripts/copy-env-from-1pass#L3. |
Thanks, but that doesn't work for me. I'm trying to pass the matched string to
Here, the ampersand should be replaced with the matched string (a date in this case). But it's a literal ampersand that gets passed to |
I would recommend you use perl too then. Take this as a base, and go crazy :)
|
ripgrep like sd also uses the same rust regex engine https://docs.rs/regex/latest/regex/ perhaps its https://github.com/greymd/teip may also be useful |
Hi and thanks for
sd
!I was wondering if it's possible with
sd
to have a command likedate
create the replacement string, wheredate
gets the matched string as an argument.I hope I can clarify this with an example.
Assume you have a file that contains dates formatted according to ISO 8601:
For some reason, all these dates need to be incremented by one day. After running
sd
, the last sentence should beIt's easy to add a day with
date
:produces
2020-02-29
.I'd love to use that
date
command withsd
to increment the dates in a file:In this made-up command, I've used
&
as a backreference to the string matched by the regex\d{4}-\d\d-\d\d
, i.e., ISO 8601 dates.I've used curly braces in the second argument to
sd
to signify that it's a command whose outputsd
should use as the replacement string.Is something like this possible with
sd
(orsed
)?Does somebody else crave that feature?
The text was updated successfully, but these errors were encountered: