Skip to content

Instantly share code, notes, and snippets.

@ryanwoodsmall
Last active May 24, 2019 18:42
Show Gist options
  • Save ryanwoodsmall/829d275dfe7e992161c29682c52b7957 to your computer and use it in GitHub Desktop.
Save ryanwoodsmall/829d275dfe7e992161c29682c52b7957 to your computer and use it in GitHub Desktop.
remove_dupes.sh
# XXX - need to pre-build daa=1 for "set -eu" scripts
function remove_dupes() {
local dstring="${1}"
local dsep="${2}"
local -A daa
local -a du
for dl in $(echo "${dstring}" | tr "${dsep}" "\n") ; do
if [ -z "${daa[${dl}]}" ] ; then
daa["${dl}"]=1
du+=( "${dl}" )
fi
done
local ne=${#du[@]}
local le=$((${#du[@]}-1))
for i in $(seq 0 ${ne}) ; do
echo -n "${du[${i}]}"
if [ ${i} -lt ${le} ] ; then
echo -n "${dsep}"
fi
done
echo
}
#!/bin/bash
#
# heavy duty bs
# why not uniq?
# because
#
function remove_dupes() {
local dstring="${1}"
local dsep="${2}"
local -A daa
local -a du
for dl in $(echo "${dstring}" | tr "${dsep}" "\n") ; do
daa[${dl}]=0
done
for dl in ${!daa[@]} ; do
if [ "${daa[${dl}]}" -eq 0 ] ; then
daa["${dl}"]=1
du+=( "${dl}" )
fi
done
local ne=${#du[@]}
local le=$((${#du[@]}-1))
for i in $(seq 0 ${ne}) ; do
echo -n "${du[${i}]}"
if [ ${i} -lt ${le} ] ; then
echo -n "${dsep}"
fi
done
echo
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment