-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add option to string replace for only outputting successful matches #3348
Comments
Yeah, this is probably a worthwhile addition. Some questions, though: How should this interact with other options, in particular --invert-match? Also, similarly, should there be an option to |
I wish we had made the original string implementation actually just do this, and also ignore the empty matches, unless perhaps we call it with a --verbose option. Also, I hate to change I wish maybe I had considered how many times I'd type out "string match", "string split" int the future and realized when this was on the drawing board it'd get very tiring for human hands (how often do you use echo a b c d | string join '-'
echo a b c d | join '-' string match (uname) "Linux"
match (uname) "Linux" Too bad. abbr can help. |
I mean: |
Well, now is the easiest time to change it.
Unfortunately, that's a no-go. GNU Coreutils and plan9port have a |
Wouldn't this be exactly the same as what I've proposed?
Is it the more common use case? I think it's not intuitive to have it behave this way per default. |
Yeah, but MySQL's |
Coreutils: any chance their behavior is similar to ours? |
Urgh, sorry. Note to self: First drink coffee, then comment. Yes, this option would be nice to have, but a similar option to only print the parts of the lines that match to
Yeah, but taking the name of something that already exists is not nice^tm. It's surprising if you're trying to execute your well-known mysql thing (I have no idea what it does, but I have a strong suspicion it's actually mysql-specific - which makes the generic name a bit annoying).
Or put into a different path, like they'd be on my machine (/usr/lib/plan9/bin/split - also executable via
Excerpt from the "--help" output:
Seems kinda similar, though I actually cannot figure out how to use this thing. I need more coffee. Seems to really want an output file. |
That looks like it's for splitting up large files to be posted on newsgroups so that a human or another utility could recombine them or something later. Pretty rare you'd already be using that in a fish script. No conflict! |
@faho asked how this would interact with the The pattern I kept running across while working on issue #2450 caused me to open issue #3955 which is effectively a duplicate of this issue as noticed by @faho. My proposal is to add a As for |
I wrote
in my previous comment. That is obviously a brain fart as the semantics of |
Currently there's no documented command line switch to make string replace only print what it replaced, and ignore everything that was not modified. I guess it's not too uncommon to want to filter a number of input lines and also transform the matching lines somehow. Currently, you have to use string match and string replace like this:
Here you have to write the
<expression>
twice, and, more importantly, you have two parsing passes. If it's a very long string, this might be much slower than having a builtin functionality to skip failed matches. What are your thoughts on this?The text was updated successfully, but these errors were encountered: