Powershell exclude HTML comment from text file -


i have config file need output text , convert csv. stuck @ first step file has few html comments excluded , remaining text used exporting csv purposes.

html comment looks following:

<!--<add name=                                />     <add name=                                />     <add name=                                />--> 

i have tried different regex's solve this, no luck. closest have got exclude first , third line using below regex, doesn't solve issue second line still present:

get-content –path c:\pathtothefile -notmatch "^\s*(<!--)|>*(-->)$" 

this regex take out line starts , not middle 1 part of comment. have multiple files multiple comments.

tried several different combos ("<!--[^>]*(-->)$") , no luck far.

your duly appreciated, thanks

in documents need process <!-- @ start of line , --> @ end? if need content, , run through loop process document line line, toggling state variable content, or not.

$data=@" <!--<add name=                                />     <add name=                                />     <add name=                                />--> a,b,c,d 1,2,3,4 "@ $state='content' $data  -split "`n" | foreach-object {   if ($_ -match '^<!--') {     $state='comment'     return $null  # because `continue` doesn't work in foreach-object   }   if ($_ -match '-->$') {     $state='content'     return $null   }   if ($state -eq 'content') {     $_   } } 

results

a,b,c,d 1,2,3,4 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -