Re: ls -R | grep char_string
Erik Steffl <steffl@bigfoot.com> writes:
> find . -type f |xargs grep char_string /dev/null
I use
find . -type f | xargs mogrep $1
where $1 is the expression to search for, and "mogrep" (below) knows
what to do with binary and compressed files. -chris
#!/bin/sh
REGEXP=$1
PRGNAME=`basename $0`
TMP=/tmp/${PRGNAME}.$$
shift
for i in $*
do
SKIP=no
GZIP=no
case $i in
*.gz)
GZIP=yes
;;
*)
;;
esac
if [ ${GZIP} = yes ]; then
if ! zcat $i | file - | grep -i text >> /dev/null 2>&1; then
SKIP=yes
fi
else
if ! file $i | grep -i text >> /dev/null 2>&1; then
SKIP=yes
fi
fi
if [ ${SKIP} = no ]; then
GREP=grep
if [ ${GZIP} = yes ]; then
GREP=zgrep
fi
${GREP} -i ${REGEXP} $i > ${TMP}
if [ $? -eq 0 ]; then
printf "$i:"
cat ${TMP}
rm ${TMP}
fi
else
# printf "'$i': Not a text file\n" 1>&2
printf hello >> /dev/null
fi
done
Reply to: