title: Making sparse matrix using awk
body: <p>I am having trouble formatting a large 2D matrix into a "sparse matrix" format. I hope someone here can help.</p>
  
  <p>Due to the large file size, an <em>awk</em> script should be prefered.</p>
  
  <p>Here is a hypothetical set from the data (tab delimited):</p>
  
  <pre><code>Regions      string8-0      string8-5000      string8-10000
  string8-0        0                2.1                1.15    
  string8-5000     0                0                  2.4  
  string8-10000    0                4                  3.1
  </code></pre>
  
  <p>So, the resulted output should be a tab separeted file with four columns. <strong>Column1</strong> = the numeric part of rownames (colomn1 from data; example: 0, 5000, 1000); <strong>Column2</strong> = is the corresponding numeric part of the colnames (example: 0, 5000, 10000), <strong>Column3</strong> = the value between the two bin. <strong>Column4</strong> = string part of column names (string8, string8, string8).</p>
  
  <p>And only print this if the corresponding value is not zero.</p>
  
  <p>like this:</p>
  
  <pre><code>0      5000    2.1    string8
  0      10000   1.15   string8
  5000   10000   2.4    string8
  10000  5000    4      string8
  10000  10000   3.1    string8
  </code></pre>
  
  <p>Sorry, if it is a redundant question, but I could not find any solutions.</p>
  
  <p>Thanks,
  Laszlo</p>