1

In below test.log file I want to search only today's date with Message "Upload_Msg_testListeningFn"; if both the conditions match then redirect the output.

cat /tmp/test.log 
===========================================================================
system Version [45.2.18] (FATAL ERROR INFORMATION)
File: [test003.cxx]
Line: [240]

Date: [19-01-2018 21:09:40]
User ID: [SYSTEM]
Message : [batman error: Upload_Msg_testListeningFn]
Error Code : [TEST0000057]
Outside FGH
Session Id: 6768678898:00:F

=======================================

Output should be:

Date: [19-01-2018 21:09:40]
Message : [batman error: Upload_Msg_testListeningFn]

I used awk but somewhere I am missing something
i used the below command for finding lines after particular date.

awk '/^Date/{c=3} c&&c--' /tmp/test.log
tripleee
  • 175,061
  • 34
  • 275
  • 318
Daya
  • 111
  • 2
  • 1
    Welcome to stack overflow, please post the sample Input_file correctly in only code tags as it is not clear as of now. – RavinderSingh13 Jan 18 '18 at 12:43
  • Please update your post with CODE TAGS, comments are not meant for it. – RavinderSingh13 Jan 18 '18 at 13:45
  • unable to add that details in required format , from File: is one line after that Line: is new line ...same till id: – Daya Jan 18 '18 at 13:46
  • See this link for code tags in SO https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks – RavinderSingh13 Jan 18 '18 at 13:52
  • date wise I have 8 ilne input file , 1 line start with system Version , 2 line start with File: , 3rd line start with Line: , 4th line start with Status: , 5th line Date: – Daya Jan 18 '18 at 14:17
  • 1
    Sorry to say NOT clear still, please update your post. – RavinderSingh13 Jan 18 '18 at 15:09
  • now it's okay... – Daya Jan 19 '18 at 07:34
  • I used awk '/^Date/{for(i=0; i<=5; i++) {getline; print}}' /tmp/test.log also but how to combine two condition. – Daya Jan 19 '18 at 07:42
  • This is a very common question. If the duplicate I selected isn't clear enough, there are several others. – tripleee Jan 19 '18 at 07:44
  • today=`date "+%d-%m-%Y"` awk '/`$today`/{c=3} c&&c--' /tmp/test.log ..... but how to $today in this case. – Daya Jan 19 '18 at 07:46
  • Yeah, that's https://stackoverflow.com/questions/19075671/how-do-i-use-shell-variables-in-an-awk-script -- not adding that as a separate duplicate. – tripleee Jan 19 '18 at 07:47
  • thanks ... I used awk '/'"$today"'/{c=4} c&&c--' filename > newfilename than grep the output which I required and set if test -s . ........my work done .....but still I searching how to combine both the output. ...any way thank you . – Daya Jan 19 '18 at 15:06

0 Answers0