1

I have an inputfile that looks like this:

<event>
foo
bar
</event>
<event>
random text
</event>

I would like to split this up into several output files, such that each file has exactly one <event>...</event>.

I tried doing this with awk, but it is not clear to me how I can redirect the output to different output files. Is it possible? Or do I have to resort to something like e.g. python?

pfnuesel
  • 5,702
  • 8
  • 35
  • 60

1 Answers1

2

If we told re awk

awk '
    /<event>/{
        start=1
        n++
    }
    start{
        print >"output" n
    }
    /<\/event>/{
        start=0
        close("output" n)
    }
    ' input.file
Costas
  • 14,806
  • 20
  • 36