Assuming you're using
bash, and the string is in a variable called
string, then
short=${string//5} should create a
short variable without any fives in it.
That doesn't address the question "How to identify the repeated digits?," but your "vector" method seem a reasonable approach.
If you don't need to use
bash, here's a
gawk program you could use
Code:
#!/bin/gawk -f
{
delete count
n=split($0,digit,"")
for (i=1;i<=n;++i) {
count[digit[i]]++
}
j=0
for (i=1;i<=n;++i) {
if (count[digit[i]]==1) {
++j
printf("%d", digit[i])
}
}
if (j) print " <- " $0
}
(If you don't want the source number, replace the
if (j) print " <- " $0 with a
if (j) print ""; else print)
With that change, I get the following with ten random five-digit numbers:
Code:
$ cat r10
23722
69450
92719
67290
42707
88180
13841
44521
06246
04079
$ gawk -f remove_dups.gawk r10
37
69450
271
67290
420
10
384
521
024
479
(You can make the
gawk program executable by a
chmod +x remove_dups.gawk where, of course, the
remove_dups.gawk is whatever you named your copy of the program.)
Note: That program will remove any duplicated character(s) in the input file, not just digits.
<edit>
By the way, the probability that a random five digit number will have a all digits different is about 1/3 (It's exactly 0.9*0.8*0.7*0.6.), so the two I got out of ten is about right.)
</edit>