Powershell to remove special characters in text file

RJ 326 Reputation points
2021-12-06T14:28:54.313+00:00

Hi there,

On executing the below script with the attached input file, looking for help to remove the special characters. How to remove them but single quotes need to be the same. You could see some special characters in output line 9,10,11,12

output

["Continental District – Denver", "Org Unit"],
["The Team Lead’**s Roadmap", "Org Unit"], --<<The single quotes in the word Lead's need to be retained>>
["Data Services
Â** - ABC", "Stem Face"],
["App tttm - CST", "Stem Face"],

script used

$file = Get-Content -Path "C:\temp\pinput.txt" -Raw
$file = $file -ireplace '(?<match1>[\"[^]])\r\n(?<match2>[^]]\"])','${match1}${match2}'
$file |Out-File -FilePath "C:\temp\oput.txt"

155372-pinput.txt
Thanks.

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. DaveK 1,871 Reputation points
    2021-12-06T17:09:09.043+00:00
    get-content C:\temp\pinput.txt -Encoding UTF8 | Set-Content c:\temp\poutput.txt
    

    I believe the output from this command retains the single quote but removes all other special characters.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.