#!/bin/sh

set +u
tmp=$1.tmp
cmd="/^$SGE_LIST.*[ ,]$SGE_ELEM[ ,]/s/[ ,]$SGE_ELEM[ ,]/ /
     /^$SGE_LIST *$SGE_ELEM$/s/ $SGE_ELEM$/ NONE/
     /^$SGE_LIST *$SGE_ELEM$/b
     /^$SGE_LIST.*[ ,]$SGE_ELEM$/s/[ ,]$SGE_ELEM$//"
sed -e "$cmd" $1 > $tmp
cc=$?
if [ $cc -eq 0 ]
then
    mv $tmp $1
    sleep 1
    touch $1
else
    echo sed failed
fi
exit $cc


