this is a done version of the previous thread. it concatenate all the arguments if they are not the same... however some case will make it a:a:b:a:b:c i try to change all the : into space and then uniq them out.... but the uniq is not working this way i guess... does anybody know why? thank you

#!/bin/sh
NP=$1
shift

for P
do
case $NP in
$P|$P:*|*:$P:*|*:$P) continue;;
*) NP="$NP:$P";;
esac
done

second=`echo $NP | tr ':' ' ' | uniq -d `
echo $second

uniq works on lines, not characters on the same line.

so is there a way to eliminate the duplicates?

Print what you want on separate lines, then use uniq ?

if i run the program >foo a a:b a:b:c it should result in a:b:c .. the uniq didn't work in the program.. i already made it line by line..... ==''

#!/bin/sh
result=$1
shift 

for next
do
  case $result in 
       $next|$next:*|*:$next:*|*:$next) continue;;
       *) result="$result:$next";;
  esac
done                                ### at this point,, all the args are concatanated 

second=`echo $result | tr ' ' ':'`   #second step, turn all space into :

IFS=:
third=`echo "$second" | tr ':' '\12'`      #third step, turn all the : into new line


four=`echo "$third" | uniq `      ###supposed to uniq the previous step.. but not successful
                                                #using sort -u will do the trick.. but i do'nt want it sorted

IFS=" "
five=`echo "$four" | tr '\12' ' ' | tr ' ' ':'`        #change the new line back to : 
six=`echo "$five" | sed -e 's/^:/.:/' -e 's/::/:.:/' -e 's/:$/:./'`       
echo $six

just to echo myself... if at the beginnig i change everything separated by space , then
foo a a:b a:b:c will be "a a b a b c"

from there if i do the for loop and case above.. it will eliminate all the duplicates.... all figured out.. thanks for the replies...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.