text files - Delete lines from multiple textfiles in PowerShell -


i trying delete lines defined content multiple textfiles.

it works in core, rewrite every file if no changes made, not cool if modifying 50 out of 3000 logonscripts.
made if statement seems doesn't work.

alright have:

#here $varfind escaped potential regex triggers. $varfindescaped = [regex]::escape($varfind)  #here deletion happens. foreach ($file in get-childitem $varpath*$varending) {     $contentbefore = get-content $file     $contentafter = get-content $file | where-object {$_ -notmatch $varfindescaped}     if ($contentbefore -ne $contentafter) {set-content $file $contentafter} } 

what variables mean:
$varpath path in logonscripts are.
$varending file ending of files modify.
$varfind string triggers deletion of line.

any highly appreciated.

greetings
löwä cent

you have read file regardless improvement on change condition help.

#here deletion happens. foreach ($file in get-childitem $varpath*$varending) {     $data = (get-content $file)     if($data -match $varfindescaped){         $data | where-object {$_ -notmatch $varfindescaped} | set-content $file     } } 

read file $data. check see if pattern $varfindescaped present in file. if filter out matching same pattern. else move onto next file.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -