Output section of file between two expressions multiple times

Attached is the exact ouput of a vmware VDR log file I am working with but what I am trying to achieve is as follows:

I need to output sections of the file using the string "Normal backup" as the start and "Duration" as the end to seperate files so I can then manipulate them further to create seperate backup logs I can then email.

I found an awk one liner which does what I need but I cannot think how to extract each section to seperate log files. I'm finding this hard to explain so here is an example.

awk '/Normal backup/,/Duration/' /tmp/backuplog.txt

So what I need is for each section it matches to then output to a seperate file (doesn't have to be awk obviously), e.g

magicshellcode > /tmp/logfile1.txt, /tmp/logfile2.txt, /tmp/logfile3.txt

etc, etc,

From there I am going to run some more shell stuff over them to tidy them up which i should be able to handle myself.

I apologise if this is hard to understand but I found it difficult to communicate without having a script to begin with.

Try this:

awk '
$4 == "Normal" && $5 == "backup"{f=1; c++}
f{print > "/tmp/logfile" c ".txt"}
$4 ~ /Duration/{f=0}
' /tmp/backuplog.txt
1 Like

Wow, Thanks! I am stoked with that response since it works perfectly!! Exactly what I was after