파일 내 포함된 텍스트를 검색하는 방법
jsp 확장자의 파일 중 setSign 이라는 텍스트가 포함된 파일을 찾는법
방법1.
find ./ -name "*.$1" -type f -exec grep "$2" {} \; -print
방법2
find ./ -name "*.$1" -type f | xargs grep "$2"
OS : IBM AIX Korn Shell
Shell 명 : tgrep.sh
#!/usr/bin/ksh
echo "#"
echo "# usage : tgrep [ -n | -list ] [-e] [확장자] [찾는문자열]"
echo "# -n : 행번호 표시"
echo "# -list : 목록만표시(중복제거)"
echo "# -e : or 조건 사용여부(egrep)"
gCmd="grep"
if [ $# = 4 ]; then
if [ $1 = "-e" -o $2 = "-e" ]; then
gCmd="egrep"
fi
if [ $1 = "-list" -o $2 = "-list" ]; then
find ./ -name "*.$3" -type f | xargs ${gCmd} "$4" | awk -F ":" '{print $1}' | sort -u
elif [ $1 = "-n" -o $2 = "-n" ]; then
find ./ -name "*.$3" -type f | xargs ${gCmd} -n "$4"
fi
elif [ $# = 3 ]; then
if [ $1 = "-list" ]; then
find ./ -name "*.$2" -type f | xargs grep "$3" | awk -F ":" '{print $1}' | sort -u
elif [ $1 = "-n" ]; then
find ./ -name "*.$2" -type f | xargs grep -n "$3"
elif [ $1 = "-e" ]; then
find ./ -name "*.$2" -type f | xargs egrep -n "$3"
fi
elif [ $# = 2 ]; then
find ./ -name "*.$1" -type f | xargs grep "$2"
fi
|
