Skip to content

Instantly share code, notes, and snippets.

@simonebaracchi
Last active December 20, 2016 11:20
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 simonebaracchi/42c7a7355e07129653c84821ce008e46 to your computer and use it in GitHub Desktop.
Save simonebaracchi/42c7a7355e07129653c84821ce008e46 to your computer and use it in GitHub Desktop.
#!/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