Skip to content

Instantly share code, notes, and snippets.

@floreo
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floreo/6380cfe7e0d2e509cd57 to your computer and use it in GitHub Desktop.
Save floreo/6380cfe7e0d2e509cd57 to your computer and use it in GitHub Desktop.
[teeworlds] convert hexa timestamp into datetime realtime log
#!/bin/bash
# may require gawk if you get the following error: function strftime never defined
# thanks to minus and guest__ for help on teeworlds IRC chan
teeworlds-server -f test.conf | gawk '{match($0, /\[([0-9a-f]+)\](.*)/, a); if(a[1]!="")$1="[" strftime("%F %T", strtonum("0x" a[1])) "]"; $1=$1a[2]; print }'
# simpler way (doesn't convert, simply dump the system's time, fflush is required to not have buffering issues)
teeworlds-server -f test.conf | gawk 'BEGIN { FS="]"; OFS=FS } /^\[.+\]/ { $1="["strftime("%F %T", systime()); print; fflush() }' &>>/var/log/teeworlds/test.log &
@floreo
Copy link
Author

floreo commented Sep 6, 2014

Convert this:
[540b27d7][datafile]: loading. filename='maps/dm1.map'

into that:

2014-09-06 17:27:19 - [datafile]: loading. filename=maps/dm1.map

@floreo
Copy link
Author

floreo commented Sep 7, 2014

Changed output format and fixed the missing quotes:
[2014-09-06 17:27:19][datafile]: loading. filename='maps/dm1.map'
Depending on your needs, you can change the output format by defining the $1 part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment