-
-
Save ayaz345/3927f4be9a86bd4f576b8a5fb15b6ee0 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Проверка аргументов | |
if [ $# -eq 0 ]; then | |
echo "Usage: $0 <input_filename> <output_filename>" | |
exit 1 | |
fi | |
# Фильтрация и чтение файла по строкам | |
grep -i '^\(@solidclass\|@pointclass\)' "$1" | while IFS= read -r line; do | |
# Функция для обработки строки | |
process_line() { | |
local result=$(echo "$1" | sed -n 's/.*= \([^:]*\).*/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') | |
if [[ -n $result ]]; then | |
result="*{{ent|$result (GoldSrc)|alt=$result}}" | |
fi | |
printf "%s" "$result" | |
} | |
# Обработка и сортировка строк | |
processed=$(process_line "$line") | |
echo "$processed" | |
done | sort > /tmp/tmpfile | |
# Создаем секции и добавляем их к текущим строкам | |
declare -A seen # Ассоциативный массив для отслеживания префиксов | |
while IFS= read -r processed_line; do | |
if [[ $processed_line =~ ^\*\{\{ent\|([^{|_]+)_ ]]; then | |
prefix="${BASH_REMATCH[1]}" | |
if [[ ! ${seen[$prefix]} ]]; then | |
seen[$prefix]=1 | |
if ((sections > 0)); then | |
printf "\n" | |
fi | |
printf "===%s_*===\n" "$prefix" | |
((sections++)) | |
fi | |
printf "%s\n" "$processed_line" | |
else | |
unincluded+=("$processed_line") | |
fi | |
done < /tmp/tmpfile > "$2" | |
# Добавляем невключенные строки | |
if (( ${#unincluded[@]} > 0 )); then | |
if (( sections > 0 )); then | |
printf "\n" | |
fi | |
printf "=== Unincluded ===\n" | |
printf "%s\n" "${unincluded[@]}" | |
fi >> "$2" | |
# Удаляем временный файл | |
rm /tmp/tmpfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment