title: Split a file based on a particular search pattern and also have a particular number of lines in the split file using AWK command
body: <p>I have a requirement where I have to split a file at an underscore pattern and the lines in the resulting file should have a maximum of 5 lines, if the result exceeds 5 lines the file name should be changed and the rest of the lines should be put in the other split files and then the result should be grouped.</p>
  
  <p><strong>For eg:</strong></p>
  
  <p>My file contains,</p>
  
  <pre><code>ADD1_5001AB
  ADD1_5002AB
  ADD1_5003BC
  ADD1_5004AB
  ADD1_5005AB
  ADD1_5006BC
  ADD1_5007AB
  ADD1_5008AB
  ADD1_5009BC
  ADD1_5010AB
  ADD1_5011AB
  ADD1_5012BC
  ADD2_5100XY
  ADD2_5101YZ
  CANC1_5200AB
  CANC1_5201BC
  CANC2_5301GH 
  CANC2_5302FG
  </code></pre>
  
  <p>So my result should have 6 files, </p>
  
  <p><strong>1st file should contain,</strong></p>
  
  <pre><code>ADD1_5001AB
  ADD1_5002AB 
  ADD1_5003BC 
  ADD1_5004AB
  ADD1_5005AB
  </code></pre>
  
  <p><strong>2nd file should contain,</strong></p>
  
  <pre><code>ADD1_5006BC
  ADD1_5007AB
  ADD1_5008AB
  ADD1_5009BC
  ADD1_5010AB
  </code></pre>
  
  <p><strong>3rd file should contain,</strong></p>
  
  <pre><code>ADD1_5011AB
  ADD1_5012BC
  </code></pre>
  
  <p><strong>4th file should contain,</strong></p>
  
  <pre><code>ADD2_5100XY
  ADD2_5101YZ
  </code></pre>
  
  <p><strong>5th file should contain,</strong></p>
  
  <pre><code>CANC1_5200AB
  CANC1_5201BC
  </code></pre>
  
  <p><strong>6th file should contain,</strong></p>
  
  <pre><code>CANC2_5301GH
  CANC2_5302FG
  </code></pre>
  
  <p>Kindly Help.</p>