Skip to content

Instantly share code, notes, and snippets.

@simonebaracchi simonebaracchi/logwalk.sh
Last active Dec 20, 2016

Embed
What would you like to do?
#!/bin/bash
# logwalk.sh is a log file browser
# Usage: logwalk.sh <logfile>
# input strings you want to filter out
# and then "open" when you want to see the full (filtered) results
# add multiple filters at once by separating them with pipes, e.g. filter1|filter2|etc
GREP=
FILTER=
HEAD=head
while true ; do
if [ "$FILTER" == "" ]; then
$HEAD "$1"
else
cat "$1" | grep -v -E "$FILTER" | $HEAD
fi
echo " --- (o)pen, (e)xit, (h)ead, (t)ail, or string to filter: --- "
read STRING
if [ "$STRING" == "e" -o "$STRING" == "exit" ]; then
exit 0
fi
if [ "$STRING" == "o" -o "$STRING" == "open" ]; then
echo Opening with filtering string: \"$FILTER\"
cat "$1" | grep -v -E "$FILTER" | less
continue
fi
if [ "$STRING" == "h" -o "$STRING" == "head" ]; then
HEAD=head
continue
fi
if [ "$STRING" == "t" -o "$STRING" == "tail" ]; then
HEAD=tail
continue
fi
if [ "$STRING" == "" ]; then
continue
fi
if [ "$GREP" == "" ]; then
GREP=$STRING
else
GREP+=("|$STRING")
fi
IFS='' FILTER="${GREP[*]}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.