27

I am running an application with command $ grails run-app which prints log in terminal like below.

search_text_terminal

What I want is search a particular text (say user authorities) in this log so that I can verify further. One way using Logging Apis to write in text file but I want to search it in a terminal at the moment.

I found similar question at how to make search a text on the terminal directly which suggests screen command, but I have no idea how screen works in this case. I tried $ screen grails run-app but couldn't move ahead.

I can see screen lists with

prayag@prayag:~/zlab/nioc2egdelonk$ screen -list
There is a screen on:
    8076.pts-2.prayag   (10/06/2013 12:13:25 PM)    (Attached)
1 Socket in /var/run/screen/S-prayag.
  • however you use screen command, but i sugggest leave it and use tmux – PersianGulf Oct 6 '13 at 8:47
  • @MohsenPahlevanzadeh, Sure I will try tmux as well. Hearing of it a lot. – prayagupd Oct 6 '13 at 10:36
20

Ctrl+a (default screen command prefix), [ (enter copy mode) followed by ?SEARCH_TEXT seems to work. Press n to go to the next occurrence. From there, you can copy words, lines, regions, etc to dump into files or paste later on (with Ctrl+a, ]).

enter image description here

  • 5
    I cannot do this. So you need to press 3 keys at once? ctrl, a, [? – Capaj Mar 17 '15 at 10:13
  • 28
    use shift+ctrl+f – Ja8zyjits Jun 3 '16 at 13:25
11

If you use Konsole (KDE terminal emulator), you can use Ctrl + Shift + F. This might work also in other (Linux) terminal emulators.

Edit:
@sumit reports this works also in Gnome Terminal.
@vdicarlo reports this also works in XFCE4 Terminal.

  • 1
    This works in GNOME terminal emulator as well. – Sumit Mar 4 '18 at 18:43
7

You can use grep after the grails command: grails run-app | grep "user authorities". However, you will have to re-run your command.

  • 3
    This answer shouldn't be voted down, its absolutely correct. – amrx Jun 1 '15 at 2:22
  • 2
    While correct, it's more useful to have something one can do after the output has already been printed. – Ludwik Sep 27 '16 at 13:13
  • @Baron I'm even pretty sure that the asker meant to imply that the command is already running, so this doesn't answer the question. – Nobody Jan 5 '18 at 21:44
2

Redirect the output to pipe and send it to a grep command:

grails run-app | grep user authorities
1

Redirect output of your command to vim-editor: grails run-app | vim -

Several tips for search using Vim:

  • type / then enter your search string user authorities
  • type :set hlsearch to highlight search results
  • type n to search forward or Shift+n to search backward
  • remember you're in editor now, so if you did some changes accidentally you can revert, just press ESC once to exit edit-mode, then press u to undo one edit
  • type :q! to exit Vim and discard your search results
  • you can do whatever you want :-D http://vim.wikia.com/wiki/Vim_Tips_Wiki

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.