title: GnuWin32 Awk in powershell script weird output (First char replaced by a space)
body: <p>I have a <code>awk</code> command that produces weird output when called from a PowerShell script. It truncates the first character of each line. If I use it in a regular batch file or in a cmd.exe terminal it works as expected. It also works as expected under Linux.</p>
  
  <p>Can someone explain why, and if possible how to fix it?</p>
  
  <p><strong>This is the command I try to execute from PowerShell:</strong></p>
  
  <pre><code>cat .\corpus_tagged.txt | gawk 'NF&gt;0' | gawk '{bo=$2\"#\"$3; printf \"%s %s %s\",$1,$2,$3; for (i=5;i&lt;=NF; i+=3) {if (bo!=$i\"#\"$(i+1)) printf \" %s %s\",$i,$(i+1);} printf \"\n\"}'
  </code></pre>
  
  <p><strong>This is the command that works from batch/cmd.exe</strong></p>
  
  <pre><code>cat corpus_tagged.txt | gawk "NF&gt;0" | gawk "{bo=$2\"#\"$3; printf \"%s %s %s\",$1,$2,$3; for (i=5;i&lt;=NF; i+=3) {if (bo!=$i\"#\"$(i+1)) printf \" %s %s\",$i,$(i+1);} printf \"\n\"}"
  </code></pre>
  
  <p><strong>The awk script in an easier to read format</strong></p>
  
  <pre><code>{
      bo=$2"#"$3;
      printf "%s %s %s",$1,$2,$3;
      for (i=5;i&lt;=NF; i+=3) 
      {
          if (bo!=$i"#"$(i+1)) 
              printf " %s %s",$i,$(i+1);
      }
      printf "\n";
  }
  </code></pre>
  
  <p><strong>My input has the following content:</strong> (corpus_tagged.txt file)</p>
  
  <pre class="lang-none prettyprint-override"><code>J' je PP1CSN00 # je PP1CSN00 1 
  aime aimer VMIP1S0 # aimer VMIP1S0 0,49045643153527  aimer VMIP3S0 0,49045643153527  aimer VMM02S0 0,0174273858921162  aimer VMSP1S0 0,000829875518672199  aimer VMSP3S0 0,000829875518672199 
  les le DA0CP0 # le DA0CP0 0,900251352385116  les PP3CPA00 0,0997486476148844 
  ananas ananas NCMN000 # ananas NCMN000 1 
  . . Fp # . Fp 1 
  Il il PP3MSN00 # il PP3MSN00 1 
  aime aimer VMIP3S0 # aimer VMIP1S0 0,49045643153527  aimer VMIP3S0 0,49045643153527  aimer VMM02S0 0,0174273858921162  aimer VMSP1S0 0,000829875518672199  aimer VMSP3S0 0,000829875518672199 
  les le DA0CP0 # le DA0CP0 0,900251352385116  les PP3CPA00 0,0997486476148844 
  chats chat NCMP000 # chat NCMP000 1 
  . . Fp # . Fp 1 
  </code></pre>
  
  <p><strong>This is my expected output:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>J' je PP1CSN00
  aime aimer VMIP1S0 aimer VMIP3S0 aimer VMM02S0 aimer VMSP1S0 aimer VMSP3S0
  les le DA0CP0 les PP3CPA00
  ananas ananas NCMN000
  . . Fp
  Il il PP3MSN00
  aime aimer VMIP3S0 aimer VMIP1S0 aimer VMM02S0 aimer VMSP1S0 aimer VMSP3S0
  les le DA0CP0 les PP3CPA00
  chats chat NCMP000
  . . Fp
  </code></pre>
  
  <p><strong>And finally, the output when calling from powershell (first char of each line is replaced by a space character</strong></p>
  
  <pre class="lang-none prettyprint-override"><code> ' je PP1CSN00
   ime aimer VMIP1S0 aimer VMIP3S0 aimer VMM02S0 aimer VMSP1S0 aimer VMSP3S0
   es le DA0CP0 les PP3CPA00
   nanas ananas NCMN000
    . Fp
   l il PP3MSN00
   ime aimer VMIP3S0 aimer VMIP1S0 aimer VMM02S0 aimer VMSP1S0 aimer VMSP3S0
   es le DA0CP0 les PP3CPA00
   hats chat NCMP000
    . Fp
  </code></pre>