Hello,
I am trying to write a script that reads names from a file called input, removes names if they have the same letter next to each other and prints the others.
e.g. Colin & John would be printed
Garry & Lynn would be removed
My thinking is that I read in each name and break it in to a substring and compare each elements neighbour with itself. If at any point array [i]= array[i\+1] the script discards the name and moves on to the next one.
My problem lies with printing the valid names. I have used a nested if statement if [ "$i" == "$((${#s}))" ]; so that once the script has reached the end of a name and it hasn't been discarded it must be valid and therefore should be printed. The script prints nothing and I am at a loss as to why. I would be very grateful if anyone could point out the flaw to me.
Regards,
Colin
***script***
var=`cat input`
for j in $var; do
s=($j)
for i in $(seq 0 $((${#s} - 1))); do
if [ "${s:$i:1}" == "${s:$[i+1]:1}" ]; then
break
if [ "$i" == "$((${#s}))" ]; then
echo $j
break
fi
fi
done
done
Contents of input*
garry
colin
john
gerry
mike
lynn