/home/lee#cat Grep
#!/bin/bash
#
(($#!=2))||[[ ! -f $2 ]]&&{ echo "Usage:$(basename $0) <patten> filename"; exit 1; }
str=$(echo $1|od -b)
str=${str% *}
str=${str#* }
patten=$(
for i in $str;do
[[ $i == 14[0-9] ]] && echo -ne "\\0133\\0${i/4/0}\\0$i\\0135" ||\
echo -ne "\\0133\\0${i/0/4}\\0$i\\0135"
done
)
while read line;do
[[ $line == *$patten* ]] && echo $line
done<$2
测试:
/home/lee#chmod +x Grep
/home/lee#cat file
abcd
aBcD
Abcabc
AbCd
aaaasadfsdf
bbb
ccc
/home/lee#grep -i abcd
/home/lee#grep -i abcd file
abcd
aBcD
AbCd
/home/lee#Grep abcd file
abcd
aBcD
AbCd
/home/lee#
|
|
|