9

I have a program that outputs some data to the terminal (via printf() ). Is it possible search a text on the outputed text on the terminal directly?

It is possible to do search by directing the texts into a file then make search on it then output the result to the terminal, but it is not what I am asking.

EDIT: what I meant by "search": I wonder if it is possible to search a text, for example how can I search libgnome-desktop on the below terminal output?

enter image description here

Angs
  • 492
  • 2
  • 7
  • 20
  • 2
    Are you looking for a terminal that supports this, or a way to do it in your current terminal? `rxvt` has this – Michael Mrozek Aug 09 '13 at 21:22
  • @Michael Mrozek: I would like to know if a terminal (especially ubuntu's terminal) has such functionality to search a text. If it is the case, how can I do it. – Angs Aug 09 '13 at 21:24

3 Answers3

16

You could use the terminal multiplexer tmux to run your program in any terminal. Then you can search through the window entering copy mode with Ctrl-b [, and use emacs (Ctrl-s) or vi (/) keywords to search for a string depending on whether emacs or vi mode is selected.

The keys available to exit copy mode are Esc or Enter for different versions of tmux.

Alternatively, some terminals support searching the window buffer, like urxvt with the searchable-scrollback Perl extension.

gypaetus
  • 921
  • 7
  • 14
4

If you were using screen, then you could go to copy mode Ctrl+a [ and then type: ?libgnome-desktop To keep searching for more instances press n for next and N for previous instance of searched string. To exit copy mode press Esc.

Additionally with screen you could press space when in copy mode to start highlighting text and press space again to copy that highlighted text. This could be pasted at the prompt or anywhere else on the terminal input with Ctrl+a ].

0

By search you mean what? find, grep or something else?

You can put the output of your printf as an argument to another command via the $() syntax

grep "$(printf "%s" 'foo')" file
Drav Sloan
  • 14,145
  • 4
  • 45
  • 43