i have this noempty.txt
Caption=http://support.microsoft.com/?kbid=3150513
CSName=DC04
Description=Update
FixComments=
HotFixID=KB3150513
InstallDate=
InstalledBy=NT AUTHORITY\SYSTEM
InstalledOn=11/29/2022
Name=
ServicePackInEffect=
Status=
for example the line "FixComments=" or "InstallDate=" or "name=" i have to add in every line the word "none"
I try whit
(Get-Content -Path c:\path\noempty.txt) | ForEach-Object {$_ -Replace '=\s', '=NONE'} | Set-Content -Path c:\path\noempty2.txt
But it doesn't work
Any advice? Thank you very much Alex
(Get-Content -Path c:\path\noempty.txt) | ForEach-Object {$_ -Replace '=\s', '=NONE'} | Set-Content -Path c:\path\noempty2.txt
for example the line "FixComments=" or "InstallDate=" or "name=" i have to add in every line the word "none"
You could read the whole file, match the parts that you are interested in and using the full match with
$0followed byNONEin the replacement.The pattern matches:
(?m)Inline modifier to enable multiline^Start of string[^\s=]+Match 1+ times a non whitespace character except for==Match literally[\p{Zs}\t]*Match optional horizontal whitespace characters$End of stringSee the regex matches.
Output
If you don't want to keep possible trailing spaces after the equals sign, you can use a capture group, and that group 1 in the replacement instead of the whole match:
See the group 1 matches.