Search using the data displayed as a result of the tail?

I am working on a Java EE application where its logs will be generated inside a Linux server.

I used the command tail -f -n -10000 MyLog It displayed the last 1000 lines from this log file.

Now I pressed Ctrl + c in Putty to disable log updates (since I fear that it might be updated with new requests and I’ll lose my data)

In the displayed result, how can I find a specific keyword? (Used / string name for search, but it does not work)

+6
source share
4 answers

Connect your output to PAGER.

 tail -f -n LINE_CNT LOG_FILE | less 

then you can use

 /SEARCH_STRING 
+7
source

Two ways:

 tail -n 10000 MyLog| grep -i "search phrase" tail -f -n 10000 MyLog | less 

The second method allows you to search with /. It will only search down, but you can press g to return to the beginning.

Edit: When testing, it seems that method 2 does not work so well ... if you press the end of the file, it will freeze until you ctrl + c with the tail command.

+5
source

You need to redirect the output from tail to the search utility (e.g. grep ). You can do this in two steps: save the output to a file, then search the file; or in one pass: display the output in the search utility

To find out what is in the file (so you can press Ctlr + c), you can use the tee command, which duplicates the output on the screen and to the file:

 tail -f -n -10000 MyLog | tee <filename> 

Then search the file.

If you want to pass the result to the search utility, you can use the same trick as above, but use your search program instead of tee

+1
source

Terminal output management on the fly

When you run any command on a Putty type terminal, you can use CTRL-S and CTRL-Q to stop and start output to Putty terminal.

String exclusion with grep

If you want to exclude lines containing a specific pattern, use grep -v , the following: delete the entire line containing the INFO line

 tail -f logfile | grep -v INFO 

Show rows that do not contain the words INFO or DEBUG

 tail -f logfile | grep -v -E 'INFO|DEBUG' 

Finally, MOTHER AND FATHER of all tail tools xtail.pl

If you have perl on your host, xtail.pl is a very good tool to learn, and in a nutshell you can use it to create multiple files. Very comfortably.

0
source

Source: https://habr.com/ru/post/914327/


All Articles