This isn't a very elegant way to do it, but see if this works for you. The code uses a fixed set of data rather than an input file, but have to replace the line "$y=$x -split "r
n"" with "$y = get-content . . ." to get the data from your file. You can remove the "here string" since it's just the contents of the data you posted.
$x=@'
"Misc expense
"Date,Ref,Payee,Amount,Note
11/04/2021,DEP,"Vendor1","5,048.34","Roof"
12/12/2021,DEP,"Vendor2","345.97","Office Supply"
,,"Misc Expense Total:","5394.31","
Misc Income
"Date,Ref,Payee,Amount,Note
11/17/2021,DEP,Vendor3,"1,000.00",
12/03/2021,DEP,Vendor4,"456.00",
,,"Misc Income Total:","1,456.00",
'@
$y=$x -split "`r`n"
$Category = ""
$Header = ""
$NewCsv = @()
ForEach ($l in $y) {
if ($l -match '(Misc expense|Misc income)$'){ # get the category
$Category = $matches[1]
continue
}
elseif ($l -match '\sTotal'){ # ignore total lines
continue
}
elseif ($l -match '(Date,Ref,Payee,Amount,Note)' ){
if ($Header.Length -eq 0){
$Header = "Category," + $matches[1]
$NewCsv += $Header
continue
}
else{
continue
}
}
elseif($l.Trim().Length -lt 1){
continue # drop empty lines
}
$NewCsv += $Category + "," + $l
}
$NewCsv | Out-File c:\junk\Clean.Csv