title: AWK split for multiple delimiters lines
body: <p>I'm trying to split a file using AWK one-line but the code below that I came with is not working properly.</p>
  
  <pre><code>awk '
  BEGIN { idx=0; file="original_file.split." }
  /^REC_DELIMITER.(HIGH|TOP)$/ { idx++ }
  /^REC_DELIMITER.TOP$/,/^REC_DELIMITER.(HIGH|TOP)$/ { print &gt; file sprintf("%03d", idx) }
  ' original_file
  </code></pre>
  
  <p>Test file is "original_file":</p>
  
  <pre><code>REC_DELIMITER.TOP
  lineA1
  lineA2
  lineA3
  REC_DELIMITER.HIGH
  lineB1
  lineB2
  lineB3
  REC_DELIMITER.TOP
  lineC1
  lineC2
  lineC3
  REC_DELIMITER.HIGH
  lineD1
  lineD2
  lineD3
  </code></pre>
  
  <p>AWK code above is for REC_DELIMITER.TOP and it is giving me these files:</p>
  
  <pre><code>original_file.split.001:
  REC_DELIMITER.TOP
  
  original_file.split.003:
  REC_DELIMITER.TOP
  </code></pre>
  
  <p>however, I'm trying to get this:</p>
  
  <pre><code>original_file.split.001:
  REC_DELIMITER.TOP
  lineA1
  lineA2
  lineA3
  
  original_file.split.003:
  REC_DELIMITER.TOP
  lineC1
  lineC2
  lineC3
  </code></pre>
  
  <p>There will be other record delimiters, and when needed, we can run for them like REC_DELIMITER.HIGH, this way getting files like below:</p>
  
  <pre><code>original_file.split.002:
  REC_DELIMITER.HIGH
  lineB1
  lineB2
  lineB3
  
  original_file.split.004:
  REC_DELIMITER.HIGH
  lineD1
  lineD2
  lineD3
  </code></pre>
  
  <p>Any help guys is very appreciate, I have been trying to get this working past few days and AWK code above is the best I was able to get. I need now help from AWK masters. :)</p>
  
  <p>Thank you!</p>