none
Replace\remove text in a line (reg key) RRS feed

  • Question

  • Normally I would just muscle through this, so I could learn as I work, but I am in a hurry, and I would really appreciate the help.

    I need the powershell to change this reg key

    FROM:

    REG_SZ   Bob:y:n:m;Fred:y:n:m;Sally:y:n:m;

    TO:

    REG_SZ   Bob:y:n:m;Sally:y:n:m;

    OR (bonus)

    REG_SZ   Bob:y:n:m;Andy:y:n:m;Sally:y:n:m;


    BlankMonkey

    Thursday, March 31, 2016 5:29 PM

Answers


  • PS C:\> help about_Operators

    Pay particular attention to the -replace operator.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by BlankMonkey Thursday, March 31, 2016 7:18 PM
    Thursday, March 31, 2016 5:32 PM
    Moderator
  • Example:

    'Bob:y:n:m;Fred:y:n:m;Sally:y:n:m;' -replace 'fred','andy'


    \_(ツ)_/

    • Marked as answer by BlankMonkey Thursday, March 31, 2016 7:18 PM
    Thursday, March 31, 2016 6:48 PM

All replies


  • PS C:\> help about_Operators

    Pay particular attention to the -replace operator.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by BlankMonkey Thursday, March 31, 2016 7:18 PM
    Thursday, March 31, 2016 5:32 PM
    Moderator
  • I see this

    Comparison Operators
          Use comparison operators (-eq, -ne, -gt, -lt, -le, -ge) to compare values
          and test conditions. For example, you can compare two string values to
          determine whether they are equal.


          The comparison operators include the match operators (-match, -notmatch),
          which find patterns by using regular expressions; the replace operator
          (-replace), which uses regular expressions to change input values; the
          like operators (-like, -notlike), which find patterns using wildcard
          characters (*); and the containment operators (-in, -notin, -contains,
          -notcontains), which determine whether a test value appears in a reference
          set.

          They also include the bitwise operators (-bAND, -bOR, -bXOR, -bNOT) to
          manipulate the bit patterns in values.

    Is this something I would stuff into an IF function??

    Also;

    I found this, will this do the trick?

    http://stackoverflow.com/questions/17099177/powershell-replacing-value-on-one-line-in-a-text-file


    BlankMonkey

    Thursday, March 31, 2016 6:41 PM
  • Example:

    'Bob:y:n:m;Fred:y:n:m;Sally:y:n:m;' -replace 'fred','andy'


    \_(ツ)_/

    • Marked as answer by BlankMonkey Thursday, March 31, 2016 7:18 PM
    Thursday, March 31, 2016 6:48 PM
  • Yeah, but I guess I am not getting the bigger picture.

    AHH HA

    This was too simple is what it is;  Perfect, ty ty ty :)

    PS C:\Users\linus> 'Bob:y:n:m;Fred:y:n:m;Sally:y:n:m;' -replace 'fred','andy'
    Bob:y:n:m;andy:y:n:m;Sally:y:n:m;
    PS C:\Users\linus> $test ='Bob:y:n:m;Fred:y:n:m;Sally:y:n:m;'
    PS C:\Users\linus> $test -replace 'fred','andy'
    Bob:y:n:m;andy:y:n:m;Sally:y:n:m;
    PS C:\Users\linus> $test ='Bob:y:n:m;Fred:y:n:m;Sally:y:n:m;'
    PS C:\Users\linus> $test = $test -replace 'fred','andy'
    PS C:\Users\linus> $test
    Bob:y:n:m;andy:y:n:m;Sally:y:n:m;

    Perfect, I can totally dump this into my script :)


    BlankMonkey

    Thursday, March 31, 2016 7:18 PM