I am trying to replace a | character within a text file. But I am not sure how to do it because the batch is not reading the |.
powershell -Command "(gc output.txt) -replace '|', ' ' | Out-File -encoding ASCII output.txt"
Which takes this input:
80853||OHNED|Mira
And outputs: 8 0 8 5 3 | | O H N E D | M i r a
Where I’d like this output 80853 OHNED Mira
Is there anyway within a batch to replace the | character?
Edit – While googling, I found out that the | character is called a vertical bar.
>Solution :
The -replace operator is regex-based; since your intent is to replace all | characters verbatim, you must escape | as \|, given that | is a regex metacharacter (a character with special meaning in the context of a regex (regular expression)):
powershell -Command "(gc output.txt) -replace '\|', ' ' | Out-File -encoding ASCII output.txt"