place delimiter when found repeated occurance

Hi all,

Searched lot in the forum but couldnt find relative post to my requirement..Looking forward for the solution.

I am basically having a huge file with repeated digits which is getting tuff to track so would want to place a delimiter in between for better clarity..

Input

4 0 4 6 4 101 1011 57 70 64 88 119 64 88 119  37
4 0 4 6 4 101 1012 62 75 115 117 122 115 117 122  37
4 0 4 6 4 101 1013 59 68 112 124 112 124  37
4 0 4 6 4 101 1021 53 71 64 64 39
4 0 4 6 4 101 1022 54 73 115 115 39
4 0 4 6 4 101 1031 57 81 64 64 39
4 0 4 6 4 101 1032 57 77 64 64 49
4 0 4 6 4 101 1041 58 80 115 115 49
4 0 4 6 4 101 1042 59 67 112 124 120 112 124 120  49

Output

4 0 4 6 4 101 1011 57 70--64 88 119--64 88 119   37
4 0 4 6 4 101 1012 62 75--115 117 122---15 117 122  37
4 0 4 6 4 101 1013 59 68--112 124--112 124  37
4 0 4 6 4 101 1021 53 71--64--64 39
4 0 4 6 4 101 1022 54 73--115-115 39
4 0 4 6 4 101 1031 57 81--64--64 39
4 0 4 6 4 101 1032 57 77--64--64 49
4 0 4 6 4 101 1041 58 80--115--115 49
4 0 4 6 4 101 1042 59 67--112 124 120--112 124 120  49

Here delimiter is placed first after 9th position then next digit is considered and searched and placed before the found string.... If you see the data with in the delimiter is the repeated data which is found later...

Thanks in advance

Shalini

Hi Shalini,
I went through your thread, and initially thought that this would be a very easy one. But when I started working on it, it really did take some time :rolleyes:
What I thought should be a 4-5 line awk code turned out to be pretty big one!!! Here's what I could come up with-

awk '
{
printf("\n%s %s %s %s %s %s %s %s %s",  $1,$2,$3,$4,$5,$6,$7,$8,$9);
i=10;
while(i<=NF)
{
nexot=i+1;
for(j=i+1;j<=NF;j++)
{
if($i==$j)
{
nexot=j+1;
}
}
if(nexot>i+1)
{
printf("  - ");
for(k=i;k<nexot-1;k++)
printf("  %s",$k);
printf(" -  %s",$(nexot-1));
}
else
{
printf("  %s",$i);
}
i=nexot;
}
}' a

Yea, I know, you might be saying there's more of C code here than awk code, but this is the best I could come up with. It did work for me, let me know if it works for you too.
Oh yea, forgot to mention, the 'a' at the end of the code is not an unwanted character(as thought of by many of my friends), but the input file which contains the input as specified by you. Enjoy!!!!