Говоря об IPv4: вы можете создать список sed-команд из вашего файла hosts:
sed -rn 's/^(([0-9]{1,3}\.){3}([0-9]{1,3}))[ \t]([^ \t]+)[ \t].*/s#\1#\4#/p' /etc/hosts > hosts.sed
Затем примените его к вашему лог-файлу:
sed -f hosts.sed LOGFILE
Конечно, ваши имена хостов должны быть перечислены в файле хоста.
Другой, обратный подход - использовать logresolve
.
С справочной страницы:
NAME
logresolve - Resolve IP-addresses to hostnames in Apache log files
SYNOPSIS
logresolve [ -s filename ] [ -c ] < access_log > access_log.new
SUMMARY
logresolve is a post-processing program to resolve IP-addresses in Apache's access logfiles. To minimize
impact on your nameserver, logresolve has its very own internal hash-table cache. This means that each
IP number will only be looked up the first time it is found in the log file.
Takes an Apache log file on standard input. The IP addresses must be the first thing on each line and
must be separated from the remainder of the line by a space.
Таким образом, вы можете использовать REGEX для извлечения всех IP-адресов, поместить их 2 раза в новый файл, один раз в первый столбец и преобразовать его с помощью logresolve. Затем используйте эту таблицу для генерации такого sedfile, как указано выше.