title: Batch file to read a txt with special characters and replace a word in it
body: <p>I'm trying to make a batch file that reads a txt file "ayylmao.txt" and find a specific word "hello" and replaces it with "xello".</p>
  
  <p>The thing is that the "ayylmao.txt" contains specific characters.</p>
  
  <p>Ayylmao.txt looks something like this:</p>
  
  
  
  <pre><code>‹‹R‹Ę‹/M‹;Ču‹č˙˙˙‹‹@‰‹‹@CëC;Đu‹čq˙˙˙‹‹@C‹D$‰;7u®‹Ó‹Ćčúţ˙˙„Ŕu3Ŕ‰YZ]_^[ĂŤ@             SVWUÄđ‰$‹ô‹‰D$‹
  ‹‹@;Č‚†   ‹Ř‹&gt;_‹ůz;ßrv;Ču!‹B‹A‹B‹)B‹x uV‹čđţ˙˙ëM‹Ř‹&gt;_‹ůz;ßu
  ‹B‹)Bë3‹Z‰\$‹&gt;‹‹.}+ű‰|$+Č‹‰HŤT$‹čMţ˙˙„Ŕu3 hello Ŕë°ë‹‹ ‰‹;D$…Y˙˙˙3ŔÄ]_^[ĂSVW‹Ú‹đţ   }ľ   ëĆ˙˙  ć  ˙˙‰sjh    Vj
  </code></pre>
  
  <p>You can see the "hello" word in the last line. I want the batch to go to the process and give me a ayylmao1.txt that looks like this:</p>
  
  
  
  <pre><code>‹‹R‹Ę‹/M‹;Ču‹č˙˙˙‹‹@‰‹‹@CëC;Đu‹čq˙˙˙‹‹@C‹D$‰;7u®‹Ó‹Ćčúţ˙˙„Ŕu3Ŕ‰YZ]_^[ĂŤ@             SVWUÄđ‰$‹ô‹‰D$‹
  ‹‹@;Č‚†   ‹Ř‹&gt;_‹ůz;ßrv;Ču!‹B‹A‹B‹)B‹x uV‹čđţ˙˙ëM‹Ř‹&gt;_‹ůz;ßu
  ‹B‹)Bë3‹Z‰\$‹&gt;‹‹.}+ű‰|$+Č‹‰HŤT$‹čMţ˙˙„Ŕu3 xello Ŕë°ë‹‹ ‰‹;D$…Y˙˙˙3ŔÄ]_^[ĂSVW‹Ú‹đţ   }ľ   ëĆ˙˙  ć  ˙˙‰sjh    Vj
  </code></pre>
  
  <p>You can see that "hello" is now "xello".</p>
  
  <p>I found this batch file that replaces a word from a text file:</p>
  
  <pre><code>@echo off
  REM -- Prepare the Command Processor --
  SETLOCAL ENABLEEXTENSIONS
  SETLOCAL DISABLEDELAYEDEXPANSION
  
  if "%~1"=="" findstr "^::" "%~f0"&amp;GOTO:EOF
  for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
      set "line=%%B"
      if defined line (
          call set "line=echo.%%line:%~1=%~2%%"
          for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
      ) ELSE echo.
  )
  </code></pre>
  
  <p>This code works for files that don't have specific characters very good if use it like this:</p>
  
  <pre><code>code.bat "hello" "xello" "ayylmao.txt"&gt;"ayylmao1.txt"
  </code></pre>
  
  <p>This code only types in ayylmao1.txt few special characters but replaces hello. I want all the special characters typed in there.</p>
  
  <p>I made it like this:</p>
  
  <pre><code>chcp 1252
  code.bat "hello" "xello" "ayylmao.txt"&gt;"ayylmao1.txt"
  </code></pre>
  
  <p>But it didn't work. It worked just like the first code.</p>
  
  <p>If there is a way in PowerShell to do this I'd be glad to hear it.</p>