title: Replacing tab with spaces to maintain n-space alignment
body: <p>I am trying to automatically compare two sets of files containing data organised into columns. There are three main issues that seem to be making this tricky:</p>
  
  <ol>
  <li>Column ordering is different between set A and set B</li>
  <li>Set A uses tabs, set B uses spaces</li>
  <li>In Set A, some columns contain blanks, Set B, they contain a default value.</li>
  </ol>
  
  <p>I have attempted to do some simple shell scripting to rearrange Set A into correctly ordered columns, e.g. <code>awk '{print substr($0, 10, 10) substr($0, 20, 10)}</code> etc, but the use of tabs within this set of files means that columns start with an inconsistent character number.</p>
  
  <p>I think the simplest solution would be to replace tabs with spaces, and then use an <code>awk</code> to rearrange the data as above. How should I go about replacing a tab with a number of spaces equal to the number needed to reach the next tab stop (for the purposes of this, lets assume 8).</p>
  
  <p>Replacing a tab with a set number of spaces obviously won't work, as I've tested below.</p>
  
  <pre><code>$ echo "A\tB\nA \tB\nA  \tB\nA   \tB\n" &gt; test
  $ cat test
  A       B
  A       B
  A       B
  A       B
  $ cat test | sed 's/\t/    /g'
  A    B
  A     B
  A      B
  A       B
  </code></pre>
  
  <p>Obviously, this could be solved by writing some code that identified what position at tab character is at, and then filling a suitable number of space characters to achieve alignment, but it seems like there should be a much simpler solution that this that I'm probably missing. (Or open every file in vim and use <code>:retab</code>, but there must be a better option!)</p>
  
  <p>Note: I am unable to <code>column</code> to rearrange data because of the blanks that exist in some datasets.</p>