Below is a description of what im trying to achieve:
Write a shell script to concatenate lists together, and output the resulting list. Do not include any argument that is a sub-list of the entire list. (The script will clean the list of any redundant items.) You must preserve the original order of the list. Remember to account for the following situations:
# a : at the beginning of the list is the same as a . at the beginning of the "list" (:/bin is the same a .:/bin)
# a :: any where in the list is the same as :.: (/bin::/etc is the same as (/bin:.:/etc)
# a : at the end of the list is the same a :. ( /bin: is the same as /bin:. )
The input to the script will be colon or space separated lists and the output will be a single colon separated list with all redundant items removed.
Examples:
prompt> clean_list a a:b a
![Thumbsup Smilie](https://www.unix.com/images/smilies/thumb.gif)
c :x: y:z
a
![Thumbsup Smilie](https://www.unix.com/images/smilies/thumb.gif)
c:.:x:y:z
prompt>clean_list apple
![Embarrassment Smilie](https://www.unix.com/images/smilies/redface.gif)
range:apple pear orange peach
apple
![Embarrassment Smilie](https://www.unix.com/images/smilies/redface.gif)
range
![Stick Out Tongue Smilie](https://www.unix.com/images/smilies/tongue.gif)
ear
![Stick Out Tongue Smilie](https://www.unix.com/images/smilies/tongue.gif)
each
The following code is where im at right now but i'm not quite getting the desired results. for example, when i try the first example above i get a result of a
c:x:y:z (not the a
c:.:x:y:z)
#!/bin/sh
for P in `echo $* | sed -e 's/^:/.:/' -e 's/::/:.:/' -e 's/:$/:./' -e 's/:/ /g'`
do
case $NP in
"") NP="$P"
;;
$P|$P:*|*:$P:*|*:$P) continue
;;
*) NP="$NP:$P"
;;
esac
done
echo $NP
Any suggestions are appreciated!!!!!