I want to read the screen log file for one the games I am hosting on a Linux (ubuntu) machine. I read it through a web interface and I only display 20 lines at a time as it would get too big for my own comfort. However, the log file keeps getting spammed with random characters. Note that it only happens to this specific game.
Here is an example:
;1m[34m[47m\[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m|[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m/[24d[m[39;49m[37m[40m[1d[0;1m[34
m[47m-[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m\[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m|[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m/
[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m-[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m\[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m|[24d[m
[39;49m[37m[40m[1d[0;1m[34m[47m/[1;58H[0m[30m[47m1[24;3H[m[39;49m[37m[40m[1d[0;1m[34m[47m-[24d[m[39;49m[37m[40m[1d[0;1m[
34m[47m\[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m|[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m/[24d[m[39;49m[37m[40m[1d[0;1m[34m[47
m-[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m\[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m|[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m/[24d
[m[39;49m[37m[40m[1d[0;1m[34m[47m-[24d[m[39;49m[37m[40m[1d[0;1m[34m[47m\[24d[m[39;49m[37m[40m
Here is the code I am using right now. It removes the unnecessary white spaces, adds a new line after 120 characters and only displays the last 20 lines of the file.
tail /srv/screenlog.0 | awk '{$1=$1};1' | sed 's/[^[:graph:] ]\+//g' | sed -e "s/.\{120\}/&\n/g" | sed -ne':a;$p;N;20,$D;ba'
I tried playing with sed in order to remove those random characters but all I did was making it worse. I really want to know if there is a way to make a patterns out of those characters and only remove the specific patterns without affecting the rest of the file.
Some linux distributions come with the utility colorize
. If you insert it into your pipeline it may help, although it won't remove all the unwanted characters, just the escape codes:
tail /srv/screenlog.0 | colorize --clean-all | awk ...