Awk solutions are great here, but here is the same approach in pure bash (> = 4)
declare -A stringmap
counter=0
while read string < INPUTFILE; do
if [[ -z ${stringmap[$string]} ]]; then
let counter+=1
stringmap[$string]=$counter
fi
done
for string in "${!stringmap[@]}"; do
printf "%d -> %s\n" "${stringmap[$string]}" "$string"
done
source
share