Try this script. It works for me under shell (sh) so hopefully it would work on your Lakka install also.
#!/bin/bash
#set -x
IFS=';'
rm Favorites.txt
ls -- *.tag > tagfiles
while read -r filename
do
while read -r gamename
do
romlist=$(echo "${filename}" | cut -f1 -d '.')
gamename="${gamename/$'\r'/}"
grep "^${gamename};" "${romlist}.txt" >> Favorites.txt
done < "${filename}"
done < tagfiles
rm tagfiles
cat Favorites.txt | sort -u Favorites.txt > tmp_favorites.txt
mv tmp_favorites.txt Favorites.txt