Domanda

Not sure if you can do this through tail and grep. Lets say I have a log file that I would like to tail. It spits out quite a bit of information when in debug mode. I want to grep for information pertaining to only my module, and the module name is in the log like so:

/*** Module Name | 2014.01.29 14:58:01
a multi line
dump of some stacks
or whatever
**/
/*** Some Other Module Name | 2014.01.29 14:58:01
this should show up in the grep
**/

So as you can imagine, the number of lines that would be spit out pertaining to "Module Name" could be 2, or 50 until the end pattern appears (**/)

È stato utile?

Soluzione

From your description, it seems like this should work:

tail -f log | awk '/^\/\*\*\* Module Name/,/^\*\*\//'

but be wary of buffering issues. (Lines printed to the file will very likely see high latency before actually being printed.)

Altri suggerimenti

I think you will have to install pcregrep for this. Then this will work:

tail -f logfile | pcregrep  -M "^\/\*\*\* Some Other Module Name \|.*(\n|.)*?^\*\*/$"

This worked in testing, but for some reason, I had to append your example text to the log file over 100 times before output started showing up. However, all of the "Some other Module Name" data that was written to the log file as soon as this line was invoked was eventually printed to stdout.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top