Skip to content

Instantly share code, notes, and snippets.

@redwallhp
Created July 6, 2015 13:58
Show Gist options
  • Save redwallhp/d4004884925f3ffcb6c7 to your computer and use it in GitHub Desktop.
Save redwallhp/d4004884925f3ffcb6c7 to your computer and use it in GitHub Desktop.
Minecraft client chat log search
#!/usr/bin/env bash
# Minecraft folder
cd /Users/your_system_username/Library/Application\ Support/minecraft
function scan_logs {
VAL="$1"
# Search for query
if [ "$(echo ${#STR})" -ge 1 ]; then
VAL="$( echo "${VAL}" | grep -i ${STR} )"
fi
# Clean up the output
CLEAN="$( echo "${VAL}" | sed 's/\[Client thread\/INFO\]:*.\[CHAT\]//' )"
echo "$CLEAN"
}
if [ -z "$1" ]; then
# Help text
echo "Usage:"
echo "--list to show available log files"
echo "--log <file> [search] to print a log file"
echo "--follow to follow live chat output"
elif [ $1 == "--list" ]; then
# Iterate log files and print their names
pref="./logs/"
suf=".log.gz"
for i in ./logs/*log.gz; do
s="${i#$pref}"
s="${s%$suf}"
echo $s
done
echo "latest"
elif [ $1 == "--log" ]; then
FILE=$2
STR=$3
if [ -z "$2" ]; then
# No file was specified
echo "You must specify a log file!"
elif [ $2 == "latest" ]; then
# Read latest.log
VAL="$( grep -Fi '[chat]' ./logs/latest.log )"
scan_logs "$VAL"
else
# Read gzipped log file
VAL="$( zgrep -Fi '[chat]' ./logs/${FILE}.log.gz )"
scan_logs "$VAL"
fi
elif [ $1 == "--follow" ]; then
tail -f ./logs/latest.log | grep -Fi --line-buffered '[chat]' | sed 's/\[Client thread\/INFO\]:*.\[CHAT\]//'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment