need to concatenate two lines if the line doesnt end with quotes

Hi

I am getting a source file where the columns are seperated by comma and double Quotes
Eg1 : "AAA","BBB","CCCC"
in the same source file i am also getting few lines where my last columns double quotes are ending in its next line or the next next line

Eg2: "AAA","BBB","CCC
CC"
(or)

"AAA","BBB","CCC
CC
CCC"
I need to concatenate all such lines( shown in Eg2) and make it in to single line (as shown in Eg1)

Can any one please help me in this regard.How can this be acheived through unix

Thanks in advance

Hi

I am getting a source file where the columns are seperated by comma and double Quotes
Eg1 : "AAA","BBB","CCCC"

in the same source file i am also getting few lines where my last column double quotes are ending in its next line or the next next line

ForEg2: "AAA","BBB","CCC
CC"
(or)

"AAA","BBB","CCC
CC
CCC"
I need to concatenate all such lines(as shown in Eg2) and make it in to single line (as shown in Eg1)

Can any one please help me in this regard.How can this be acheived through unix

Thanks in advance

$ cat file.txt
"AAA","BBB","CCC
CC"
"AAA","BBB","CCC
CC
CCC"
$ awk '{if(substr($0,length)=="\"") print;else printf("%s",$0);}' file.txt
"AAA","BBB","CCCCC"
"AAA","BBB","CCCCCCCC"

Cross posted:

Hey
Thanks a lot its working
:slight_smile:

How can we acheive this using "sed" command

root@isau02:/data/tmp/testfeld> cat infile
"AAA","BBB","CCC
CC"
"AAA","BBB","CCC
CC
CCC"
root@isau02:/data/tmp/testfeld> sed -e :a -e '/[^"]$/ { N; s/\n// ;ta}' infile
"AAA","BBB","CCCCC"
"AAA","BBB","CCCCCCCC"

Thanks for You reply

the Above mentioned commands are working for records like

Eg: "AAA","BBB","CCC
CC"
(or)

"AAA","BBB","CCC
CC
CCC"

But there are some more record in the source files
Eg: "AAA","BBBB","Cccc""XYZ""
CCC"

How can i concatene such kind of records

my output should be
Result:---> "AAA","BBBB","Cccc""XYZ""CCC"...... how can i acheive this

That's a new aspect.

root@isau02:/data/tmp/testfeld> sed -e :a -e '/^"[aA]/ { N; s/\n//; ba }' infile | sed '{ s/"[aA]/\n&/g }'| sed '1d'
"AAA","BBB","CCCCC"
"AAA","BBB","CCCCCCCC"
"AAA","BBBB","Cccc""XYZ""CCC"

With Perl:

$ cat file
"AAA","BBB","CCC
CC"
"AAA","BBB","CCC
CC
CCC"
"AAA","BBB","CCCC"
"AAA","BBBB","Cccc""XYZ""
CCC"

$ perl -0pe's/("?.*?)\n(?!"|\Z)/$1/g' file
"AAA","BBB","CCCCC"
"AAA","BBB","CCCCCCCC"
"AAA","BBB","CCCC"
"AAA","BBBB","Cccc""XYZ""CCC"