title: How to extract every N columns and write into new files?
body: <p>I've been struggling to write a code for extracting every N columns from an input file and write them into output files according to their extracting order. </p>
  
  <p>(My real world case is to extract every 800 columns from a total 24005 columns file starting at column 6, so I need a loop)</p>
  
  <p>In a simpler case below, extracting every 3 columns(fields) from an input file with a start point of the 2nd column. </p>
  
  <p>for example, if the input file looks like:</p>
  
  <pre><code>aa 1 2 3 4 5 6 7 8 9 
  bb 1 2 3 4 5 6 7 8 9 
  cc 1 2 3 4 5 6 7 8 9 
  dd 1 2 3 4 5 6 7 8 9 
  </code></pre>
  
  <p>and I want the output to look like this:
  output_file_1:</p>
  
  <pre><code>1 2 3
  1 2 3
  1 2 3
  1 2 3
  </code></pre>
  
  <p>output_file_2: </p>
  
  <pre><code>4 5 6  
  4 5 6 
  4 5 6 
  4 5 6 
  </code></pre>
  
  <p>output_file_3:</p>
  
  <pre><code>7 8 9
  7 8 9 
  7 8 9
  7 8 9
  </code></pre>
  
  <p>I tried this, but it doesn't work:</p>
  
  <pre><code>awk 'for(i=2;i&lt;=10;i+a) {{printf "%s ",$i};a=3}' &lt;inputfile&gt;
  </code></pre>
  
  <p>It gave me syntax error and the more I fix the more problems coming out.</p>
  
  <p>I also tried the linux command cut but while I was dealing with large files this seems effortless. And I wonder if cut would do a loop cut of every 3 fields just like the awk.</p>
  
  <p>Can someone please help me with this and give a quick explanation? Thanks in advance.</p>