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:
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
Last edited by Scott; 02-09-2010 at 09:38 AM..
Reason: Code tags
Here are a couple exemples of the type of paragraph ending I might run into in those log files:
26/01/2010 00:56:51 FIN DES TRAITEMENTS DE FIN DE JOURNEE
----- Traitement termine -----
26/01/2010 00:57:22 VSRECYQS : DM-ibut de l'M-idition des opM-iration recyclM-ies
26/01/2010 00:57:22 Fin de traitement deVSRECYQS terminM-i avec succM-hs
----- Traitement termine -----
26/01/2010 00:59:16 Nombre d'enregistrements en anomalie: 000000
26/01/2010 00:59:16 Fin - Traitement operations ayant atteint la date limite
----- Traitement termine -----
26/01/2010 01:29:10 MC28B5TB : Mise M-` jour des services et des interventions terminM-i
----- Traitement termine -----
If i'm not mistaken, what you do here is stock every line in a variable, print it if it matches a pattern and then replace its value with the next line after that test ?
If i'm not mistaken, what you do here is stock every line in a variable, print it if it matches a pattern and then replace its value with the next line after that test ?
I tried running this.
dsh -w server1 'lsof /audit | awk '{ print $2 }''
It did not like above so I tried to escape the single parenthesis at the end.
dsh -w server1 'lsof /audit | awk '{ print $2 }\''
It then hung so I changed up the parenthesis to this. This worked.
dsh -w server1... (6 Replies)
Hi,
I have 2 .txt pads containing data.
I need a script which reads content of one .txt file, performs some operations and calculates a number which is stored in a variable.
Now , all the content of another .txt pad should be appended to first .txt pad at pre calculated nth line number.
... (4 Replies)
Hi,
I need to read a string with ; separated using loop one filed by one field and perform some operation. Can you please check and let me know how to print command parameterised.
key=phani;ravi;kiran
number_of_keys=`echo $key|awk '{print NF}' FS=';'`
for (( i = 1; i <= $number_of_keys;... (4 Replies)
Hi i have a control file which i need to read. It is ',' separated. the 3rd parameter will be ';' separated.
I have 2 files:
/home/orig.txt
/home/join.txt
I need a O/P file name based on firstparameter_1.txt and it should have the content of /home/orig.txt
and appended content from... (2 Replies)
Hi! all
can any one tell me how to compare current record of column with next and previous record in awk without using array
my case is like this
input.txt
0 32
1 26
2 27
3 34
4 26
5 25
6 24
9 23
0 32
1 28
2 15
3 26
4 24 (7 Replies)
Hi,
I made an executable file in terminal and it looks like this.
echo Enter the name of the file without the .wig extension
read NAME
echo Enter the ratio
read RATIO
awk '{$2*=$RATIO;{print $0}}' ${NAME}.wig > ${NAME}normalized.wig
I have a file with several million lines that look... (6 Replies)
I am trying to figure awk.
I have a file in my home directory called testawk.sh, have made it executable, and have run it... But don't see any output.
This is the contents of the file:
#!/usr/bin/awk -f
{ print " - HI -" }I enter ./testawk.sh in the prompt, press enter, and watch as the... (2 Replies)
Hi all,
I'm writing a program in bourne shell that compresses a file 3 different ways then displays a table of data with the compression type, original file size, compressed size and compression ratio. I've written most of it but reached 2 problems that won't allow me to finish it correctly.
The... (2 Replies)
The goal:
I have a list of people in teams. The list looks something like this
$1 = Job Position (marketing, IT, PR)
$2 = Name
$3 = Team Name
$4 = Targeted member (somebody in field 2 targets somebody else)
$5 = Employment Status (full time/part time/etc)
The idea is to search through... (2 Replies)
This is probably a fairly simple question but I cant seem to get it to work.
Im trying to multiply an entire column in a file by a variable in my bash script but just cant seem to get it to work with awk.
Here is what I'm trying
$varr is some value
$line is my file
awk '{print... (1 Reply)