Question: I have a csv file like below. Sometimes there is line feed in the middle column. is there any way to replace line feed in unix with space using sed, awk or anything else? -

```
COLA,COLB,COLC,COLD
test,test2,"test3",test4
test5,"test6
test666
test67","test7",test8
test9,test10,test11,test12

```

in above data the second record is actually one record - 

```
test5,"test6
test666
test67","test7",test8

```

Answer: 
Perl to the rescue!

```
perl -MText::CSV_XS=csv -we 'csv( in    => "file.csv",
                                  on_in => sub { $_[1][1] =~ s/\n/ /g } )'

```

`on_in` specifies a callback to handle input; `$_[1]` contains the current row, so `$_[1][1]` corresponds to column 1 (0-based, i.e. the 2nd column).

See [Text::CSV\_XS](http://p3rl.org/Text::CSV_XS).
This might work for you (GNU sed):

```
sed -E ':a;/^(([^",]*,)*("[^"]*",)*)*"[^"]*$/{N;s/\n/,/;ta}' file

```

If a line contains an unmatched `"`, append the next line, replace the newline by `,` and repeat.