Replacing LF in quoted strings

I have a file in the format:

"Product 1"|"Code 1"|"Description 1"|"Supplier 1"<LF>
"Product 2"|"Code 2"|"Description 2<LF>is complex"|"Supplier 2"<LF>
"Product 3"|"Code 3"|"Description 3"|"Supplier 3"<LF>

where is the line-feed character.

A downstream system is reading this file as:

"Product 1"|"Code 1"|"Description 1"|"Supplier 1"<LF>
"Product 2"|"Code 2"|"Description 2<LF>
is complex"|"Supplier 2"<LF>
"Product 3"|"Code 3"|"Description 3"|"Supplier 3"<LF>

I want to replace the character within double-quotes ONLY (example below) so that the downstream system processes three lines:

"Product 1"|"Code 1"|"Description 1"|"Supplier 1"<LF>
"Product 2"|"Code 2"|"Description 2!!!LF!!!is complex"|"Supplier 2"<LF>
"Product 3"|"Code 3"|"Description 3"|"Supplier 3"<LF>

How can I achieve this?

Thanks.

Is this a question? :smirk:

If this line feed only appears in one particular column you could use Import-Csv and treat only the affected cell. :man_shrugging:t3:

Please read the post!

There is an embedded character in the 3rd field of the second record.
And no, the embedded could be anywhere in the record.

I did.

I got this.

What record? :thinking:

So you have to set up a regex pattern to find and replace all line feed characters not followed by a double quote … :man_shrugging:t3:

I think Olaf was pointing out that you missed some clarification, specifically

I suspect this is actually suppose to read where <LF> is the line-feed character. Otherwise some may read that as a question or get confused on what you’re actually asking for. Please understand there’s a lot of different folks from different places and sometimes things can be misunderstood quite easily.

In any case I think Olaf’s suggestion is probably a way forward. Regex can be helpful here I think and \n is the line feed character for regex. Might be able to create a capture group based on the required criterion then update as needed.

Play around on regex101 or any other regex tester of your choice. I have used regex101 quite a bit in the past and it works well in PS in my experience.

Thanks for the clarification of the confusion - didn’t refer back to the post to see how this wasn’t clear.