Answer the question
In order to leave comments, you need to log in
Is it possible to replace variables with PowerShell?
Good afternoon.
There is a file, let's call it params.ini, with the following content:
{param: variable1} = sample1
{param: variable2} = sample2
{param: variable3} = sample3
There is a Test directory, with nested directories and files.
The task is to get the values of variables from the params.ini file using the PowerShell script and replace them in all found files of all directories in the Test folder by mask, suppose in all *.sql, *.json, *conf files.
Help me please.
Answer the question
In order to leave comments, you need to log in
Something like
$params [email protected]{}
Get-Content d:\params.ini | foreach-object {
If $_ -match '\[param:(^]+)\]\s*=\s*(.*)' { $params[$matches[1]}=$matches[2] }
}
$filelist = get-childitem d:\work *json,*sql
Foreach $file in$filelist {
Get-content $file | foreach-object {
If $_ -match 'Тут нужный regex для файла' -and $params.contains($matches[1]){
$_=$_ - replace 'тут тоже регекс', $params[$atches[1])
}
} |set-content $file
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question