Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script help

Status
Not open for further replies.

anatazi

Programmer
Jun 24, 2002
33
0
0
US
Hi
I need to use the script below to make a script that concatenate 2 lists together so 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.
I would appreciate any help and pointers to get me started.

#!/bin/sh

for P in `echo $PATH | sed -e 's/^:/.:/' -e 's/::/:.:/' -e 's/:$/:./' -e 's/:/ /g'`

do
case $NP in

"")

if [ -d "$P" ]
then
NP="$P"

fi

;;
$P|$P:*|*:$P:*|*:$P)
continue
;;

*)
if [ -d "$P" ]
then
NP="$NP:$P"

fi

;;
esac
done

echo $NP


 
can you give an example of what you want your output to look like ?
 
An example would be; if the intput is a a:b a:b:c :x: y:z
the output would look like a:b:c:.:x:y:z,
Thanks
 
Code:
echo $PATH | sed '
s/^:/.:/
s/:$/:./
s/::/:.:/g
b loop
:loop
s/^\([^:]*\)\(:.*\)\{0,1\}:\1:/\1\2:/
s/\(:[^:][^:]*\)\(:.*\)\{0,1\}\1:/\1\2:/
t loop'

Input
Code:
a:a:b:a:b:c::x::y:z
gives
Code:
a:b:c:.:x:y:z
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top