Hello all,
I'm a beginner to shell/ awk script writing, and I'm trying to do something that looks like it shouldn't be (too) hard at all to do, but unfortunately, I can't seem to be able to find the right way to do it with awk.
I need to look for the time several processes start & end in a couple log files. Getting the beginning of each process was fairly simple, I just need awk to get the right patterns but i'm at a loss as far as the ending time of those processes are concerned:
Those log files look like that:
26/01/2010 00:56:51 FIN DES TRAITEMENTS DE FIN DE JOURNEE
----- Traitement termine -----
I need to get the line before the one with : " ----- Traitement termine ----- " which states the time each process ended.
The first trick is no two processes will display the same ending message before the common " ----- Traitement termine ----- " message -> so I obviously can't look for any pattern there.
I thought "piece of cake", I just need to find all lines matching that " ----- Traitement termine ----- " pattern and ask awk to print the previous record...
So here is the script I wrote to do so:
awk ' BEGIN {split($0,ligne,"\t")}
/[A-Z]tape/ {print $1" " $2" " $3" " $4" "$5 >> "tmp"}
/Lancement/ {print "Lancement le : "$2 " a " $3 >> "tmp"}
/Traitement termine/ {print ligne[NR-1] >> "tmp"} 'log
I don't get any error message, but I don't get any result with the last search either.
The second trick is I also tried defining RS as " ----- Traitement termine ----- " to be able to print the last few fieds of each record to get what I need, but I can't either since some of those records would then be bigger than the 3kb awk is limited to...
I can't seem to find the right syntax to do so. Or may be this is not the way it should (can) be done ?
Any help will be most welcome. Thanks in advance
Muadib