-
Notifications
You must be signed in to change notification settings - Fork 140
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
Operations on capture groups #172
Comments
Looking through the issues specifically for something like this. But my case is a bit different. When I think "operation" I think any shell command with input that generates an output. Whereas what In my project I'm probably going to implement this with |
The how would also be interesting, but I expect that it will involve matching, piping, transforming, and finally replacing. While this is always good to know, the original intention was to request support for basic operations, in order to make them possible with a single simple P.S.: when the operation becomes that complex
I prefer to write a full-fledged program, that can be a Rust one if efficiency is required (using |
I think that's fair but I do like operating in the shell to reduce dependencies :) |
Personally, I quite like how much you can do with jq. The syntax is terse, if a bit hard to remember - not unlike sed or other "original" tools really. But you can do quite a lot quickly if you can google or get use to it. I reckon some commands in the replace expression might work well with sd's approach. As we have the
Sure there are more examples, but I am too busy as I type to think of some. Where sed uses a different command represented by a letter (e.g. |
@stellarpower thanks for the syntax proposal, I like the idea of the command inside some delimiters. I would always keep the group identifier, and use a different separator, like However, to delete and keep lines you don't need a specific command: you just have to use multi-line mode [with the E.g.: # delete
sd --flags m '^.*,[:space:]*,.*$\n' '' your-file.txt
# keep
# not really working with sd, because the `regex` crate does not support look around
sd --flags m '^.*(?!SIG[[:alpha:]]+ received.*$\n' '' your-file.txt For more information about the look around you can have a look at this SO answer and the suggested replacement http://www.formauri.es/personal/pgimeno/misc/non-match-regex/?word=foo However, a practical answer is that, if you want to operate line-wise, just use ripgrep: # delete
rg -v ',[:space:]*,' your-file.txt > new-file.txt
# keep
rg 'SIG[[:alpha:]]+ received' your-file.txt > new-file.txt It is based on the same |
I'd like to have some flexibility about how to use the captured text.
My specific use case is about case: I'd like to lower case the matched text.
Possible with
sed
:https://stackoverflow.com/a/1814396/8653979
The text was updated successfully, but these errors were encountered: