Append next line to previous line when one pattern not found

Hi,
I need help for below scenario.I have a flat file which is having records seperated by delimiters which will represent each record for oracle table.My Control file will consider each line as one record for that table. Some of the lines are aligned in two/three lines so that records are rejected by scripts.
I need help to align the data as expected.

Input will be like below:

PC111111^|test1^|....   ->Line1-Its inserted corretly
PC222222^|test2^|
asdgasdgaj^|                ->Line2 seperated into two records so its considered as bad record.

Please help me with command that will append next line with previous line if PCXXXXXX pattern is not found as first word in each line.

I have tried with

sed -e :a -e '$!N;s/\n[^PC]//;ta' -e 'P;D'

But its not appending if the next line starts with "P","^" and "C".:wall:

Any inputs are greatly appreciated.:b:

try this:

awk '/^PC/{a[NR]=$0}!/^PC/{a[NR-1]=a[NR-1]$0}END{for(i=0;i<NR;i++){print a}}' file

Thanks Kato. Its working fine.

Alternatively, as you initially thought, sed proves more concise:

 sed '/^PC/{N;/\nPC/!{s/\n//};P;D}' file

Another concise one-liner using Perl -

$
$ cat -n f20
     1  PC111111^|test1^|....   ->Line1-Its inserted corretly
     2  PC222222^|test2^|
     3  asdgasdgaj^|
     4  gjeucowkje^|
     5  wwwdixoeum^|
     6  PC333333^|test2^|
     7  PC444444^|test2^|
     8  fjaldkdjgk^|
     9  PC555555^|test2^|
$
$ perl -0pe 's/\n([^PC])/$1/g' f20
PC111111^|test1^|....   ->Line1-Its inserted corretly
PC222222^|test2^|asdgasdgaj^|gjeucowkje^|wwwdixoeum^|
PC333333^|test2^|
PC444444^|test2^|fjaldkdjgk^|
PC555555^|test2^|
$
$

tyler_durden