Combine multi-row cell into a single line

My CSV file looks similar to this example (the K, L, and M are in the same cell as J but each on a new line within that cell):

1,  A,  B,  C,  D
2,  E,  F,  G,  H
3,  I,   J  N,  O,
          K
          L
          M,
4,  P,   Q,  R,  S

I would like to have it look like this:

1,  A,  B,  C,  D
2,  E,  F,  G,  H
3,  I,   J K L M,  N,  O
4,  P,   Q,  R,  S

Any ideas on how I can reformat that multi-line cell?

We can give you better answers if you tell us what UNIX you have and what shell you are using - please post the output of these two simple commands:

echo $SHELL
uname -a

/bin/bash

Linux 2.6.32-696.28.1.el6.x86_64 #1 SMP Thu Apr 26 04:27:41 EDT 2018 x86_64 x86_64 x86_64 GNU/Linux

I don't understand what you're trying to do.

Is it that for any line that does not start with a number you want to add the text of that line to the 3rd field of the previous line just before the last space in that field? What happened to the comma after the O in your input file?

What have you tried to solve this problem on your own?

Where are you stuck trying to get the results you want?

On top of what Don Cragun did ask, can this spread happen to other cells as well? How to tell which cell is involved? Are there additional control chars in the cell indicating a split?

Combine data with the Ampersand symbol (&)
Select the cell where you want to put the combined data.
Type = and select the first cell you want to combine.
Type & and use quotation marks with a space enclosed.
Select the next cell you want to combine and press enter. An example formula might be =A2&" "&B2.

Are you able to install csvtool or csvkit ? I know the former is able to work with multiline cells in a csv file; I don't know about the latter.

csvtool has a "call command" option allowing it to call a shellscript or shell function to modify the file one line at a time.

I think for the example you gave:

flatten() { echo "$1","$2","${3//$'\n'/ }","$4","$5" }
export -f flatten
csvtool call flatten file.csv

This is untested and you will have to try it out.

csvtool has the ablilty to cut and paste columns just like the cut and paste tools, so it might be easier to pull out the problem column, fix it as above. and paste it back into the original file.

I think you need version 4 of bash to get the $'' functionality, or look at using tr : tr '\r' ' '

Andrew