0

I read a csv file that contains currency symbol : us dollar ($), british pound (£) and euro (€). Here a short extract:

337;European €;NULL;
426;British £;NULL;
337;Americain $;NULL;

I use a powershell command to replace the "NULL" literal string in the file by an empty string :

(Get-Content %OutputFile%) -replace 'NULL', '' | Out-File -encoding unicode %OutputFile%

But the Get-Content don't correctly read the currencies symbols and return this :

337;ODEYEUREU;hf;Odey European €;;
426;INFLECGB;hf;Inflection Point C £;;
337;ODEYEUREU;hf;Odey European $;;

If the dollar is OK, the pound is prefixed by an expected character and the euro symbol is not display.

What encoding to use to handle all currency symbols (that I can specify in a inline command) ?

VyTre
  • 103
  • 3
  • 14
  • I launched a powershell command from a batch file to replace the string "NULL". Because I've not found the DOS equivalent. And I can't rewrite the full batch to ps file. – VyTre Sep 27 '22 at 15:08
  • 2
    Try `(Get-Content %OutputFile% -Encoding utf8) -replace 'NULL', ' '` – Itchydon Sep 27 '22 at 15:14

1 Answers1

1

You have to specify UTF8 encoding on both the Get-Content side and the Out-File side otherwise it might infer (guess) that you are trying to read in ASCII content. Otherwise the Out-File will take the mis-encoded content and output it "wrong". Try this:

(Get-Content %OutputFile% -Encoding UTF8) -replace 'NULL', '' | Out-File -Encoding UTF8 %OutputFile%
HAL9256
  • 12,384
  • 1
  • 34
  • 46
  • 1
    Nice, but note that `Get-Content` in Windows PowerShell assumes the system's _ANSI_ code page in the absence of a BOM, not _ASCII_. By contrast, in PowerShell (Core) 7+ UTF-8 is now the consistent default, across all cmdlets, and - unlike in Windows PowerShell with `-Encoding utf8` - a BOM-_less_ UTF-8 file is created by default (use `-Encoding utf8BOM` if you need one). – mklement0 Sep 27 '22 at 15:39