Home > front end >  Replacing the contents or following text of a keyword in Powershell
Replacing the contents or following text of a keyword in Powershell

Time:12-27

I want to replace the contents of a certain keyword or text in a .txt file Example:

word.pass=haiwueuofbdkoabqo1738379

I want to replace the contents or text of word.pass=

I only know about replacing a certain keyword but not the following text or the line

CodePudding user response:

In it's simplest form you can look for a line that starts with word.pass= and replace the whole line:

$a = "word.pass=haiwueuofbdkoabqo1738379"
if ($a -like "word.pass=*") {
    $a = "word.pass=SomeNewText"
}
write-host $a

This answers the question you've posted, but I suspect that there's more to this.

  • Related