2

Right now I am on MacOS, and I am using iterm2 as my terminal app. It's got some great features but one limitation is that when I use ctrl-f to search for something, it will highlight the results in yellow, but it won't filter out the non-matching results. I am looking for a way to filter out all non-matching lines, using the terminal application. What I mean, is it would only display stuff in the terminal, that matched what was being searched for - which will eliminate the need for a lot of scrolling up and down.

Does anyone know if iterm2 can do this, or should I be looking for another terminal app?

6
  • 1
    My inner Unix greybeard says you should be using tools like grep to do this rather than relying on features of your terminal emulator.
    – Spiff
    Commented Oct 16, 2018 at 18:30
  • grep can't do dynamic filter like that and I can't afford to restart the process, should I just shut down the server? Makes no sense. I know what you are saying, but only an end-user application that actually displays the text can do this AFAICT. Commented Oct 16, 2018 at 18:30
  • 2
    Oh, so you have output in the terminal emulator's scrollback buffer that you can't regenerate? That's a bummer. You could always do Cmd-A, Cmd-C, pbpaste | grep somesearchstring.
    – Spiff
    Commented Oct 16, 2018 at 18:36
  • I guess I have to make a video to get it across. I can increase the buffer size to 100K lines which is more than enough. What I am trying to do - when I search for "fooxoaogeg" I only want the one line that matches that to show up in the terminal, then when I undo the filter, all the unmatched lines reappear on the screen. Commented Oct 16, 2018 at 19:16
  • 1
    I understand exactly what you want, but I don't know whether Terminal.app or iTerm2 provide a GUI way to do it (which is why I didn't post an Answer), so I provided a way to do something very similar in any terminal emulator. Namely: select all, copy, (optionally open a new window here), use the "pbpaste" command to send the pasteboard (clipboard) contents to stdout, pipe it to grep and have grep filter on your string or regex, (optionally close the new window here). It's not as sweet as what you want, but it might be a decent workaround.
    – Spiff
    Commented Oct 16, 2018 at 19:40

1 Answer 1

0

https://github.com/junegunn/fzf does a pretty good job here, you can do

$ my_command | fzf --tac

and I think get exactly what you're looking for.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .