Hi All,
i have a csv file .
In the 7th column i have data that has line feed in it.
Requirement is to remove the line feed from the 7th column whenever it appears
There are 11 columns in the file
C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11
The value in C7 contains line feed ( Alt + Enter ), since the end of the line is also line feed value is C7 is pushed to different line .
1) 1,b2,c3,d4,e5,f6,here comes the line feed ,g8,h9,i10
this is pushed to second line
the output is :
1,b2,c3,d4,e5,f6,here comes the line feed
this is pushed to second line , g8,h9,i10
kindly advice
awk -F"," '{if(NF>7){for(i=8;i<=NF;i++){a=a","$i;$i=""};NF=7;print $0;getline;gsub(/^ */,"");OFS="";print $0,a}else{print $0}}' OFS="," file.csv
use Text::CSV;
my $csv = Text::CSV->new({binary=>1});
#NOTE: Replace input.txt with your actual filename
open(my $in, "<input.txt") or die "input: $!\n";
#NOTE: Replace output.txt with the name you want for your new file
open(my $out, ">output.txt") or die "output: $!\n";
while(my $colref = $csv->getline ($in)) {
s/[\r\n]//g foreach (@$colref);
$csv->combine(@$colref);
print $out $csv->string . "\n";
}
close($in);
close($out);
Reference : How to remove all CR/LF from a line except last one? : Database Export, Perl, Remove CR and LF