in reply to delimited file with multiline columns.
G'day Karim,
Welcome to the Monastery.
Firstly, I concur with ++haukex' response: Text::CSV is the appropriate tool for this task.
"After many attempts at using perl regexes, I am still stuck!"
In some other situation, where you simply want to convert a multi-line string to a single-line string, and preserve line-endings if they exist, you can use this regex:
s/\R(?!\z)//gm
Here's a quick command line test:
$ perl -E 'my @x = ("a\nb\nc\n", "a\nb\nc", "abc\n", "abc"); for (0 . +. $#x) { say "$_=|$x[$_]|"; $x[$_] =~ s/\R(?!\z)//gm; say "$_=|$x[$_] +|" }' 0=|a b c | 0=|abc | 1=|a b c| 1=|abc| 2=|abc | 2=|abc | 3=|abc| 3=|abc|
See also: "perlrebackslash: \R"; "perlre: Lookaround Assertions"; perlre.
Caveat: \R was introduced in v5.10.0: you'll need at least that version of Perl.
— Ken
|
|---|