title: Edit CSV header field with powershell
body: <p>hope someone can help with PowerShell questions. 
  I have a file like this</p>
  
  <p>test1.dat</p>
  
  <pre><code>H,customername,4110,001,69,001
  d,item,desc,number
  d,item,desc,number
  d,item,desc,number
  </code></pre>
  
  <p>What I would like to do is to change replace the last column (001) with the left 3 digits from the 3rd column(4110)</p>
  
  <p>so it will be like this:</p>
  
  <pre><code>H,customername,4110,001,69,411
  d,item,desc,number
  d,item,desc,number
  d,item,desc,number
  </code></pre>
  
  <p>I only want to modify the headers and not the details. I tried the code below. </p>
  
  <pre><code>$file = "C:\files\test1.dat"
  
   (Get-Content  $file)[0 .. 0] | Foreach-Object {$_ -replace "411", "001"} | 
  Set-Content  $file
  </code></pre>
  
  <p>the problem with this is
  I have not found a way to use replace with left string to get the first 3 char from a field. 
  This code will delete the details and only writes the first line. </p>
  
  <p>Any help will be helpful,</p>
  
  <p>thanks</p>