Remove Multi-Line String from File with PowerShell


hello

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

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...