I have a text file with multiple lines. Many are blank, or so I am assuming from looking at the file contents. I would like to write/print only the lines that contain text. I am having trouble. Here is my code:
$test = Get-Content -Path '.\dummy-file.html'
# convert html file to text, save only the relevant info (no tags)
foreach ($line in $test) {
$newline = $line -split ("<.*?>") -split ("{.*?}") # remove html and css tags
$newline -replace "`n","" # thought this would get rid of blank lines. it doesn't
$newline >> "test-ouput.txt" # save to new file
}
# read text file, print only lines with text
$test.ForEach({$_ -notmatch "`n"})
The above doesn't work, prints only booleans to the console, and even then, their values are wrong. The correct output, given the first 10 lines of $test, should be only two lines of text, eight of them are blank. However, the blank lines are printed.
I am new to regex, assuming it has something to do with that. My understanding of PowerShell is also novice. Thanks.