Replace the content of a textfile with a regex in powershell

Yes, you can do that in one line and don’t even need a pipeline, as -replace works on arrays like you would expect it to do (and you can chain the operator):

(Get-Content Input.json) `
    -replace '"(\d+),(\d{1,})"', '$1.$2' `
    -replace 'second regex', 'second replacement' |
  Out-File output.json

(Line breaks added for readability.)

The parentheses around the Get-Content call are necessary to prevent the -replace operator being interpreted as an argument to Get-Content.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)