Last active
May 24, 2019 18:42
-
-
Save ryanwoodsmall/829d275dfe7e992161c29682c52b7957 to your computer and use it in GitHub Desktop.
remove_dupes.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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