Simple grep Wrapper

by J. Edward Durrett

Unix/Linux / text searching

Most people who have spent time around Unix systems are familiar with the grep command. In both day to day
administration and in investigating issues, grep makes it quick and easy to find text within a file. Sometimes
though, I don’t know what I am looking for. That leads the output of history to look something like this:

grep someword /path/file
grep anotherword /path/file
grep yetanotherword /path/file

That is a lot of typing and it can go on for a while. There are of course some shell tricks to make it less
typing, like using the up arrow key, but I wanted something that was even faster. So I wrote this very simple
script (also available at github https://github.com/durrettj/gwrap/:
#!/bin/sh
file=$1
search=null
clear
while [ "$search" != "!q" ]; do
printf "\n\nEnter search term/phrase or '!q' to exit: "
read search
clear
printf "Results of search:\n\n"
grep -r "$search" $file | more
done

Now if I have some logfile or a directory full of emails, I can quickly run a couple of word searches to find what
I am looking for. This really helps when searching less predictable human generated text where multiple words have
similar intent.







Copyright (c) 2019, Jason Edward Durrett - All content on this site, unless otherwise noted, is subject to this license.

Please contact me if any errors, such as erroneous / misleading content or missing / incomplete attribution, are found.