Grep a section from an UNIX file obtaining only part of the data

Hello,

I have a log file that has several sections "BEGIN JOB, End of job" like in the following example:

19/06/12 - 16:00:57 (27787398-449294):  BEGIN JOB j1(27787398-449294) JOB1

19/06/12 - 16:00:57 (27787398-449294):  DIGIT: 0
 number of present logs : 1
19/06/12 - 16:00:57 (27787398-449294):  The file /users/file1.dat.A0003HSI was rename to /users/file1.dat.001
19/06/12 - 16:00:57 (27787398-449294):  Sent to SERVER1 for transmission
19/06/12 - 16:00:57 (27787398-449294):  End of job j1(27787398-449294) JOB1

From each of these sections I need to extract the following data, if possible, with the following output format.

JOB1;SERVER1;file1.dat

Can you guide me through a possible way to do that?
Thanks a lot in advance.

Try

awk '/BEGIN JOB/, /End of job/ {if (/BEGIN JOB/ || /file/) print $NF; if (/Sent/) print $(NF-2)}' file
JOB1
/users/file1.dat.001
SERVER1
1 Like

Try:

awk '/Sent/{S[$4]=$8} /rename/{F[$4]=$NF} /End of job/{print $NF, S[$4], F[$4]}' OFS=\; file
JOB1;SERVER1;/users/file1.dat.001
1 Like

Thanks!!! It works perfectly!!!!

Hello mvalonso,

Could you please try following once.

awk '
BEGIN{
  OFS=";"
}
/BEGIN JOB/{
  if(value){
     print first,value,prev
  }
  value=first=prev=""
  flag=1
  first=$NF
}
flag && /file/{
  value=(value?value OFS:"")$NF
}
/End of job/{
  flag=""
  next
}
{
  gsub(/.*Sent to | for.*/,"")
  prev=$0
}
END{
  if(value){
     print first,prev,value
  }
}
'    Input_file

Thanks,
R. Singh