Good Evening Folks -
I have a need to search a specific directory and ALL sub-directories for the following string:
Data Load Updated
If this string is found, I need to print content from the line directory above it between [] symbols, as well as the file name where it is found.
Here is a sample file content:
[Tue Mar 07 15:08:31 2017]Local/GENJBAPP/Fin_Plan/admin@Native Directory/209240/Info(1013166)
Received Command [Import] from user [admin@Native Directory] using [FCSTCD.rul]
[Tue Mar 07 15:08:31 2017]Local/GENJBAPP/Fin_Plan/admin@Native Directory/209240/Info(1003040)
Parallel dataload enabled: [1] block prepare threads, [1] block write threads.
[Tue Mar 07 15:08:31 2017]Local/GENJBAPP/Fin_Plan/admin@Native Directory/209240/Info(1003037)
Data Load Updated [648] cells
[Tue Mar 07 15:08:31 2017]Local/GENJBAPP/Fin_Plan/admin@Native Directory/209240/Info(1003053)
Data Load Elapsed Time with [FCSTCD.rul] : [0.011] seconds
[Tue Mar 07 15:08:31 2017]Local/GENJBAPP///175440/Info(1013210)
User [admin@Native Directory] set active on database [Fin_Plan]
[Tue Mar 07 15:08:31 2017]Local/GENJBAPP///176308/Info(1042059)
Connected from [::1]
[Tue Mar 07 15:08:31 2017]Local/GENJBAPP/Fin_Plan/admin@Native Directory/176308/Info(1013091)
Received Command [Calculate] from user [admin@Native Directory]
Therefore, if this string is found in 'Application1.log' for instance, the results file should contain:
Application1.log
Tue Mar 07 15:08:31 2017
Is this possible?
Thank you!
---------- Post updated at 07:41 PM ---------- Previous update was at 06:36 PM ----------
I came up with this solution and it seems to be working fine:
find /home/oracle/Hyperion_Batch/Scripts/Batch -type f | xargs awk '{A[NR]=$0}/Data Load Updated/{print A[NR-1]}'>>output.txt
If this is not the correct approach, please let me know.