From 0fd747cb77b40c28f5a5e09ab8097353a94ddd61 Mon Sep 17 00:00:00 2001 From: Deepankar Chakroborty <35454738+dchakro@users.noreply.github.com> Date: Sun, 26 Nov 2023 22:16:34 -0800 Subject: [PATCH] code for searching the logfile --- brewlog.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brewlog.sh b/brewlog.sh index 63aa8d0..07838da 100644 --- a/brewlog.sh +++ b/brewlog.sh @@ -27,6 +27,7 @@ OPTIONS: --brew-help Show brew commands (alias to "brew help") version Show brewlog version info archive Archives the current log file as .xz (gzip as fallback if xz not found) + search [TERM] Searches for TERM in the logfile. (Uses grep) tail [-n INT] Show the last "INT" lines from the log file. (default: last 15 lines) @@ -83,6 +84,9 @@ elif [ "$1" == "tail" ]; then tail -n 15 "$LOGFILE" exit 0; fi +elif [ "$1" == "find" ]; then + # Listing all appearances of search term in the log file. + cat "$LOGFILE" | egrep "$2" elif [ "$1" == "archive" ]; then if [ -f "$LOGFILE" ] ; then # Archiving logfile i.e. brew.log is removed (will be created on next run)