Inplace editing
A combination of
get-content,
set-content and the
-replace string
operator allows to edit a file
in place (much as might be done in
Linux with
sed -i).
The following (simple)
pipeline modifies
some.text: it replaces
#text# with
"Hello world" and
#num# with
42.
$fileName = 'some.text'
( get-content $fileName ) `
-replace '#text#', '"Hello World"' `
-replace '#num#' , 42 |
set-content $fileName
Thus
The text is #text# and the
number is #num#.
becomes
The text is "Hello World" and the
number is 42.