Need help with text file parse


i know powershell (enough by); however, have ran issue in cant find answer on google..

have test.audit file (for example) contains

<check_type>        <custom_item>                system              : "linux"         type                : "check"         description         : "8.1.1.2 other text blah blah"     </custom_item>           <custom_item>                system              : "linux"         type                : "check"         description         : "8.1.1.1 more text blah blah"     </custom_item>           <custom_item>                system              : "linux"         type                : "check"         description         : "8.1.1.3 text blah blah"     </custom_item>        </check_type> 


looks xml file, not in traditional format i'm use to. 

anyway, using test.audit file.. trying delete entire "custom_item" string contains description of "8.1.1.1".

new file like

<check_type>        <custom_item>                system              : "linux"         type                : "check"         description         : "8.1.1.2 other text blah blah"     </custom_item>                <custom_item>                system              : "linux"         type                : "check"         description         : "8.1.1.3 text blah blah"     </custom_item>        </check_type> 


the thing has replied me on forum create parser, when makes seem single line of text only. 

can me this..

thanks

there smarter way, worked me:

[xml]$weirdfile = get-content 'c:\users\mikecrowley\desktop\new folder\file.txt' $resultsarray = $weirdfile.check_type.custom_item | {$_ -notlike '*description         : "8.1.1.2*'}  #display results $resultsarray


mike crowley | mvp
my blog -- baseline technologies



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Motherboard replacement

Cannot create Full Text Search catalog after upgrading to V12 - Database is not fully started up or it is not in an ONLINE state

Remote Desktop App - Error 0x207 or 0x607