Remove Multi-Line String from File with PowerShell
attempting remove string file using powershell. string file.
code can read file not remove string other file. whats going wrong , how can fix it?
$inputfile = ".\usermenutest1.4d"
$outputfile = ".\usermenutest2.4d"
$destinationfile = "$outputfile.new"
# read input file variable
$target = [io.file]::readalltext($inputfile)
# replace target in output file
(get-content $outputfile) | foreach-object {
$_ -replace $target, ''
} | set-content $destinationfile
here proposal:
cd <yourpath> $original = (get-content ".\usermenutest2.4d") $pattern = '(' + $((get-content ".\usermenutest1.4d") -join '|') + ')' $original | foreach-object { $_ -replace $pattern} >> <youroutputfile>hope works in test run,
wizend
yeah, guys moved on... witness: http://social.technet.microsoft.com/forums/en-us/winserverpowershell/thread/8a4393f1-9ca6-46d3-933c-07217fa12695/#8a4393f1-9ca6-46d3-933c-07217fa12695
we'll never hear him again.
inspired carlsberg.
Windows Server > Windows PowerShell
Comments
Post a Comment