[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: format grep ouput



BartlebyScrivener wrote:
On Jul 15, 4:20 pm, Jeff D <fixedo...@gmail.com> wrote:

probably the easiest thing to do is write up a little wrapper for grep
like so:
#!/bin/sh
if [ -z $1 ] ; then
         echo "please enter file type"
         exit 1
         fi

if [ -z $2 ] ; then
         echo "please enter search pattern"
         exit 1
         fi

for FILE in `find . -type f -name "*$1" -exec  grep -il $2 {} \; ` ; do

echo " " ; echo "**" ; echo $FILE

grep --color -i $2 $FILE


Wow. That's a whole education in bash scripting.  I think it will
work. It chokes on directories with spaces in them, but that's because
I haven't renamed all the dirs I copied over from Windows yet. I will.

The following works with filenames with spaces.  It
displays the filename after the text match, though.

find . -type f -name "*$1" -exec sh -c "grep --color -i $2 '{}' && \
        echo '**** echo {}' && echo" \;



Reply to: