I have a real channel delimited file clutter that I need to load into the database. The file has 35 fields and therefore 34 pipes. One of the fields consists of HTML code, which for some records includes several line breaks. Unfortunately, there is no place where the line falls.
The solution I came up with is to count the number of pipes in each line and until that number reaches 34, remove the new line symbol from this line. I am not incredibly good at Perl, but I think I'm close to achieving what I'm looking for. Any suggestions?
use strict;
open (FILE, 'test.txt');
while (<FILE>) {
chomp;
my $line = $_;
$line =~ tr/\x00//;
my $count = ($line =~ tr/|//);
while ($count < 34) {
$line =~ tr/\r\n//;
$count = ($line =~ tr/|//);
print "$line\n";
}
}
source
share