I am creating a script that will copy a file, rename it and then look inside to remove certain special characters. One of these special characters is some sort of ASCII apostrophe that I cannot replicate with keys. I can copy and paste it though, however the replace function doesn't work.
Opens file > Searches for strange apostrophe ’ and replaces with nothing. I'd like it to replace it with a normal apostrophe but I don't know how this is done, and at current the biggest problem is that I can't get it to "see" this strange apostrophe that winds up in the autogenerated file I'm modifying. Any help much appreciated. Thanks :)
Apostrophe in file: ’
Normal Apostrophe: '
This is a chunk of the batch that I've isolated to test with.
@echo off
set YYMMDD=%DATE:~-2,2%%DATE:~-7,2%%DATE:~-10,2%
set DDMMYYYY=%DATE:~-10,2%%DATE:~-7,2%%DATE:~-4,4%
set YYYY-MM-DD=%DATE:~-4,4%-%DATE:~-7,2%-%DATE:~-10,2%
powershell -Command "(gc 'C:\LOCATION\Client_List_%DDMMYYYY%.csv') -replace '’', '' | Out-File 'C:\LOCATION\Client_List_%DDMMYYYY%.csv'"
Echo Done
That strange apostrophe
’isU+2019Right Single Quotation Mark, supposedly a closing quote. It could be paired with a different opening quote. In above example,‘isU+2018Left Single Quotation Mark.Get-Help 'about_Quoting_Rules'saysIn fact, PowerShell accepts two different sets of quotes:
"“”„'‘’‚‛AFAIK, all those quotation marks are present in most Windows ANSI code pages (1252, 1250, 1257, 1253, 1251, 1254, 1255, 1256, 1258) so they may be used literally in
ANSI-saved.batscript - except the latter quotation mark‛U+201BSingle High-Reversed-9 Quotation Mark. In such case, use$([char]0x201B)instead of'‛‛'as follows:or as follows:
Analysis and explanation
Next PowerShell code snippet shows an excerpt from Unicode database (character names ending with
Quotation Markor containingApostrophe):(Output from modified
Get-CharInfocmdlet.) OriginalGet-CharInfomodule is downloadable from http://poshcode.org/5234.Next PowerShell script completes above results by showing some valid (and invalid in my locale) combinations of quotes:
Output:
Note that
⹂ U+2E42 DOUBLE LOW-REVERSED-9 QUOTATION MARKis present in Unicode database and is properly rendered in PowerShell ISE.Addendum: I found more candidates of quotation marks (shown merely result obtained from
Excerpt_From_UnicodeDataTxt.ps1script):