'How can i convert a sed command to its PowerShell equivalent?

Editor's note:

  • The macOS sed command below performs an in-place (-i '') string-substitution (string-replacement) operation on the given file, i.e. it transforms the file's existing content. The specific substitution shown, s/././g, replaces all non-newline characters (regex metacharacter .) with verbatim . characters, so be careful when trying the command yourself.

  • While the intended question may ultimately be a different one, as written the question is well-defined, and can be answered to show the full PowerShell equivalent of the sed command (a partial translation is in the question itself), notably including the in-place updating of the file.


I have a mac command and i need it to run on windows. I have no experience in mac whatsoever.

sed -i '' 's/././g' dist/index.html

After research i found that i should use

get-content path | %{$_ -replace 'expression','replace'}

but can't get it to work yet.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source