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

Flag to only output matched lines #150

Open
tyilo opened this issue Mar 9, 2022 · 3 comments
Open

Flag to only output matched lines #150

tyilo opened this issue Mar 9, 2022 · 3 comments
Labels
M-needs triage Meta: Maintainer label me!

Comments

@tyilo
Copy link

tyilo commented Mar 9, 2022

It would be nice to have an option to only output matched lines:

$ cat test.txt
foo aaa bar
baz
foo bbb bar
$ sd 'foo (.*) bar' '$1' < test.txt
aaa
baz
bbb
$ sd --only-matched-lines 'foo (.*) bar' '$1' < test.txt
aaa
bbb
@igorcafe
Copy link

igorcafe commented Apr 16, 2022

Just to add to your request:
I think it could have a match, without needing to pass a replace argument.
For example:

$ echo "hello 123 there!" | sd -m '\d+'
123

@stellarpower
Copy link

I'd like ot ech othe above. I would like to extract and modify some lines in a document. Example being a naïve parse of an HTML document. I'd like to extract some tags, and discard the rest. It would be nice to be able:

  • to output only the matched section of a line
  • to output only the lines thatr were matched
  • combine these two, so that lines with no match are discarded; the segments of the line not included in the match are discarded.

@alexilyaev
Copy link

Adding to the request. Using --preview on a large file prints the whole file instead of just the affected lines, making it unusable.
Such a flag would help a lot.

Note about the upcoming potential --diff flag:
#238 (comment)

I still think that -p should have a flag to show only the affected lines and not print the whole file.

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

5 participants