Splitting a line with pattern in Sed - Unix

I have a file with single line, that line contains just like the following sample

00200100293^30^1^bla bla ...._______To:	zabell00200100293^30^3^aSub00200100293^30^4^ellaCc:	Sanders,De on my desk__________00200100293^30^4^___________________________________00A00ABC0293^30^1^something___To:	some text00A00ABC0293^30^3^aSub00A00ABC0293^30^4^ellaCc:	__________00A00ABC0293^30^4^___________________________________

I want to spilt up in to multiple line based on 00200100293^, 00A00ABC0293^ and etc...

00200100293^,00A00ABC0293^ - These numbers could be any thing but alpha-numeric the length is always fixed 11 digits followed by '^'. Basically the output should like the following.

00200100293^30^1^bla bla ...._______To:	zabell
00200100293^30^3^aSub
00200100293^30^4^ellaCc:	Sanders,De on my desk__________
00200100293^30^4^___________________________________
00A00ABC0293^30^1^something___To:	some text
00A00ABC0293^30^3^aSub
00A00ABC0293^30^4^ellaCc:	__________
00A00ABC0293^30^4^___________________________________

I am trying this one

cat inputfile |sed "s/^.\{11\}^/~/^.\{11\}^/g" |tr -s "~" '\n' >output

but it does not give me anything which I wanted, Can any one know how to resolve this. Much appreciated

Thanks

$ sed 's,00200100293,|&,g;s,00A00ABC0293,|&,g' infile | tr '|' '\n'

Thanks, but the 00200100293^ and 00A0ABC0293^ are not the only values are in the file. it contains many different string but the length is always same with 11 digits followed by "^"

 
$ nawk -F^ '{for(i=1;i<=NF;i++){if(length($i)>11){printf("^%s\n%s",substr($i,1,length($i)-10),substr($i,length($i)-10,length($i)))}else{printf("^%s",$i)}}}' inputfile
^00200100293^30^1^bla bla ...._______To: zabell0
00200100293^30^3^aSub0
00200100293^30^4^ellaCc: Sanders,De on my desk__________0
00200100293^30^4^___________________________________00
0A00ABC0293^30^1^something___To: some text00
0A00ABC0293^30^3^aSub00
0A00ABC0293^30^4^ellaCc: __________00
0A00ABC0293^30^4^_________________________

Reposting the correct input:

input:

00200100293^30^1^bla bla ....To: zabell00200100293^30^3^aSub00200100293^30^4^ellaCc: Sanders,De on my desk__________00200100293^30^4^___________________________________00A0ABC0293^30^1^something___To: some text00A0ABC0293^30^3^aSub00A0ABC0293^30^4^ellaCc: __________00A0ABC0293^30^4^____________________________

...
...
etc...

output:

00200100293^30^1^bla bla ....To: zabell
00200100293^30^3^aSub
00200100293^30^4^ellaCc: Sanders,De on my desk
___
00200100293^30^4^___________________________________
00A0ABC0293^30^1^something___To: some text
00A0ABC0293^30^3^aSub
00A0ABC0293^30^4^ellaCc: __________
00A0ABC0293^30^4^___________________________________

...

 
$ nawk -F^ '{for(i=1;i<=NF;i++){if(length($i)>11){printf("^%s\n%s",substr($i,1,length($i)-12),substr($i,length($i)-10,length($i)))}else{printf("^%s",$i)}}}' infile 
^00200100293^30^1^bla bla ...._______To: zabel
00200100293^30^3^aSu
00200100293^30^4^ellaCc: Sanders,De on my desk_________
00200100293^30^4^___________________________________
0A00ABC0293^30^1^something___To: some text
0A00ABC0293^30^3^aSub
0A00ABC0293^30^4^ellaCc: __________
0A00ABC0293^30^4^_______________________

Thanks a lot. It works fine. Thanks again.

---------- Post updated at 05:27 AM ---------- Previous update was at 05:20 AM ----------

Thanks Kamaraj,

One more help.

Instead of returning 8 single line.. is it possible to get 2 single line for the above example.. something like.

00200100293^30^1^bla bla ....To: zabel aSu ellaCc: Sanders,De on my desk_____________________________________
0A00ABC0293^30^1^something___To: some text aSub ellaCc: _________________________________

Just wondering..

Thanks

sed 's/\([0-9ABC]\{11\}^\)/\n\1/g'

For two lines in stead of 8. Assuming you always have 8....

sed 's/\([0-9ABC]\{11\}^\)/\n\1/5'

The above will insert the newline (\n) before the 5th occurrence of a string of 11 characters from 0-9 and A, B and C followed by one ^.

Thanks. But it's not always 8 lines. It can have n number of lines

This will probably take some pre-work.

I imagine:

Counting the number of "fields" in each line and pre-pending it to the lines using awk -F^ '{print NF, $0}'

Parsing the file line by line in a script
Letting the "script" adjust the sed command above using some math, such as

cat $INPUTFILE | awk '{print (NF/2)+1,$0}' | while read CUTPOINT REMAINDER
do
  echo $REMAINDER | sed 's/\([0-9ABC]\{11\}^\)/\n\1/'${CUTPOINT}
done

I have not checked whether Linux' stupid read function accepts input from a while loop. I seem to recall that it doesn't.

Regardless that can be worked around. More concerning is that sed is instantiated for every line from the original input file.

I am able to figured it out.

Thanks