title: How to extract one column from multiple files, and paste those columns into one file?
body: <p>I want to extract the <strong>5</strong>th column from <em>multiple</em> files, named in a <em>numerical</em> order, and paste those columns in <em>sequence</em>, side by side, into <strong>one</strong> output file.</p>
  
  <p>The file names look like:</p>
  
  <pre><code>sample_problem1_part1.txt
  sample_problem1_part2.txt
  
  sample_problem2_part1.txt
  sample_problem2_part2.txt
  
  sample_problem3_part1.txt
  sample_problem3_part2.txt
  ......
  </code></pre>
  
  <p>Each problem file (1,2,3...) has two parts (part1, part2).  Each file has the same number of lines.
  The content looks like:</p>
  
  <pre><code>sample_problem1_part1.txt
  1 1 20 20 1
  1 7 21 21 2
  3 1 22 22 3
  1 5 23 23 4
  6 1 24 24 5
  2 9 25 25 6
  1 0 26 26 7
  
  sample_problem1_part2.txt
  1 1 88 88 8
  1 1 89 89 9
  2 1 90 90 10
  1 3 91 91 11
  1 1 92 92 12
  7 1 93 93 13
  1 5 94 94 14
  
  sample_problem2_part1.txt
  1 4 330 30 a
  3 4 331 31 b
  1 4 332 32 c
  2 4 333 33 d
  1 4 334 34 e
  1 4 335 35 f
  9 4 336 36 g
  </code></pre>
  
  <p>The output should look like: (in a sequence of <em>problem<strong>1</strong>_part<strong>1</em></strong>, <em>problem<strong>1</strong>_part<strong>2</em></strong>, <em>problem<strong>2</strong>_part<strong>1</em></strong>, <em>problem<strong>2</strong>_part<strong>2</em></strong>, <em>problem<strong>3</strong>_part<strong>1</em></strong>, <em>problem<strong>3</strong>_part<strong>2</em></strong>,etc.,)</p>
  
  <pre><code>1 8 a ...
  2 9 b ...
  3 10 c ...
  4 11 d ...
  5 12 e ...
  6 13 f ...
  7 14 g ...
  </code></pre>
  
  <p>I was using: </p>
  
  <pre><code> paste sample_problem1_part1.txt sample_problem1_part2.txt &gt; \
       sample_problem1_partall.txt
   paste sample_problem2_part1.txt sample_problem2_part2.txt &gt; \
       sample_problem2_partall.txt
   paste sample_problem3_part1.txt sample_problem3_part2.txt &gt; \
       sample_problem3_partall.txt
  </code></pre>
  
  <p>And then:</p>
  
  <pre><code>for i in `find . -name "sample_problem*_partall.txt"`
  do
      l=`echo $i | sed 's/sample/extracted_col_/'`
      `awk '{print $5, $10}'  $i &gt; $l`
  done    
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>paste extracted_col_problem1_partall.txt \
        extracted_col_problem2_partall.txt \
        extracted_col_problem3_partall.txt &gt; \
      extracted_col_problemall_partall.txt
  </code></pre>
  
  <p>It works fine with a <em>few</em> files, but it's a crazy method when the number of files is large (over <strong>4000</strong>).
  Could anyone help me with simpler solutions that are capable of dealing with multiple files, please? 
  Thanks!</p>