I have a CSV file containing address information that will occasionally have linebreaks within a field. This results in our software seeing this as two separate lines with invalid data. My final goal is to create a one-line Powershell command that can be run from the terminal to fix this, however, I cannot for the life of me get "-replace" to work correctly when bringing capture groups into the equation.
Here is the data file with line endings that can be captured with "\r\n":
"name1","address1","city1","state1","zip1"
"name2","address2
2ndline2","city2","state2","zip2"
Here is what I have so far (not in the 1 line cmd line format yet):
((get-content "$local\$file" -raw) -replace '(?sm),"[^"]*(?<line>\r\n)[^"]*",', '''${line}<replace>''') `
-replace "<replace>","" | Set-Content "$local\test2.txt"
I ran into issues figuring out how to replace a capture group with nothing, so I am trying to replace it with another string that I can then remove easily. When I run the above command, it replaces the entire match instead of just the capture group. I created this line of code based on another suggestion here: https://stackoverflow.com/a/29973460/6477292