Show date/time with tail|grep command

Hi,

I have a log file without date/time, and I want that everytime tail|grep find something it displays the date/time and the line. I have tried something like this command but without any luck to display the date/time:

tail -F catalina.out | sed "s/^/`date `/" | egrep 'Fatal|delimiter|structures'

It displays the date/time but the date/time when I executed the command, not when the match happened.

Any ideas?

Thanks.

We need to see several lines from catalina.out - above and below a matched line -- to answer your question.

Why? It's a log file without date and time.

/apps/tomcat-pub/webapps/paudio/v1/WEB-INF/resources/xml/
bCaducat [false] bControlCarregaOk [true]
/apps/tomcat-pub/webapps/paudio/v1/WEB-INF/resources/xml/
Emissora CATCULTURA bControlPrioritariOk [false] bNowAndNextOk [true] bControlCarregaOk [true]
[Fatal Error] pritmes:347:209: The element type "xsl:template" must be terminated by the matching end-tag "</xsl:template>".
file:///apps/tomcat-pub/webapps/pritmes; Line #347; Column #209; org.xml.sax.SAXParseException: The element type "xsl:template" must be terminated by the ma
tching end-tag "</xsl:template>".
/apps/tomcat-pub/webapps/paudio/v1/WEB-INF/resources/xml/
bCaducat [false] bControlCarregaOk [true]
/apps/tomcat-pub/webapps/paudio/v1/WEB-INF/resources/xml/

Ok- then you tell us how to know when the line in the logfile was written. If the file was written out over a period of time the file mtime is LAST time it was written to - the time for the last line in the file - not the time a given line was written.

Without timestamps or some other file with timestamps you cannot get anything but a file mtime - or a ctime which in this case is pretty much useless.

If you show me the last time it was written to it's ok to me :slight_smile:

tail -f catalina.out  | egrep 'Fatal|delimiter|structures' |
while read record
do
	ls -l catalina.out | read f1 f2 f3 f4 f5 f6 f7 f8 restofline
	echo "$f6 $f7 $f8: $record"
done 

start with this

SOLVED

tail -F catalina.out | egrep --line-buffered 'Fatal|delimiter|structures' | awk '{ print strftime("%c") " " $0}'