title: Batch / Powershell replace first 2 characters from string for each line in file
body: <p>I have this database that looks like this:</p>
  
  <pre><code>......
  CL8596
  593005
  CM3059
  MADX0051
  510043
  MD0059
  512128
  MADX0088
  ......
  </code></pre>
  
  <p>What i need to do is to replace entries starting either with 59 or 51 with 'CLME' and 'MADE' respectively, so that it looks like this:</p>
  
  <pre><code>......
  CL8596
  CLME3005
  CM3059
  MADX0051
  MADE0043
  MD0059
  MADE2128
  MADX0088
  ......
  </code></pre>
  
  <p>I am scratching my head, searching for a solution, but can't seem to find anything. </p>
  
  <p>My only solution so far is for entries starting with letters like MD0059: </p>
  
  <pre><code>(Get-Content .\t.txt) | ForEach-Object { $_ -replace "md", "madr" } | Set-Content .\t.txt . 
  </code></pre>
  
  <p>This will not work for replacing numbers, since some entries already contain "59" and "51"</p>
  
  <p>Thank you in advance !</p>
  
  <p>Edit:</p>
  
  <p>This solution works:</p>
  
  <pre><code>(Get-Content .\t.txt) | ForEach-Object -Process {
  if ($_ -match '^51')
  {
      $_ -replace '^51','MADE'   
  }
  elseif ($_ -match '^59')
  {
      $_ -replace '^59','CLME'
  }
  else
  {
      $_
  }
  } | Set-Content .\t.txt
  </code></pre>
  
  <p>Thank you user3482697.</p>