Wednesday, April 4, 2012

grep -r in Hp-Ux // Recursive grep in Hp-Ux


We can use the below script to search recursively in hp-ux. We can added this to path. so that we can run it directly any time.

#!/usr/bin/sh
typeset DIR=$1
typeset PAT=$2
find ${DIR} -xdev -type f | while read FILE
do
[ `file ${FILE} | grep -c ascii` -eq 0 ] && continue
grep "$PAT" ${FILE} /dev/null
done
exit 0