powershell - Search and Replace in files from windows command prompt -
i've 2 files properties.txt
key1=value1 key2=value2
and template.txt uses file
$key1 xcvsdf sfd $key1 sdf $key2 lorem $key2 ipsum
i want replace properties properties.txt template.txt , write file. don't want run on python\java runtime since should run on machine without prerequirements
how can using powershell? batch files?
assuming needs able run on powershell 2.0, do:
# read template file $template = get-content .\template.txt # copy template result variable $result = $template # loop through list of properties get-content c:\dev\properties.txt |foreach-object{ # split each line key-value pairs $key,$value = $_ -split '=',2 # replace placeholder appropriate value $result = $result -replace ('\${0}' -f $key),$value } # output final result $result |out-file .\result.txt
Comments
Post a Comment