There is no easy way to achieve what you require, and any solution will be highly dependent on the data. For this reason, if your spreadsheet contains other data that is not arranged in this manner I would advise copying the multi-line cell ranges to a separate spreadsheet and working on them in isolation.
One option is to use a macro, as this can be programmed to iterate over the lines in each cell, which is essentially what you require. Exactly what this macro would look like I have no idea, but it will use the same type of logic as the sed
expression given below.
Another option is to export the multi-line cells to CSV and run a pattern matching expression over the data to replace the newline characters. Exporting to CSV should provide content like:
"Cell1Line1
Cell1Line2
Cell1Line3"
"Cell2Line1
Cell2Line2"
"Cell3Line1
Cell3Line2
Cell3Line3
Cell4Line4"
A sed
expression like this[1]:
$ sed ':a;N;$!ba;s/\([^\"]\)\n/\1\",\"/g' multi-line_cells.csv > single_line_cells.csv
… will produce:
"Cell1Line1","Cell1Line2","Cell1Line3"
"Cell2Line1","Cell2Line2"
"Cell3Line1","Cell3Line2","Cell3Line3","Cell3Line4"
… which can be re-imported and copied as required.
[1] Refer here for details about what the loop and branch part of the expression (:a;N;$!ba;
) does, and here for details about the capture group part of the expression (\([^\"]\)
and \1
).