正则的形式如下
`expr "$str" : '.*\(substr\)'`
因为如果substr中包含有特殊字符时就比较麻烦.暂时想到有什么能一句就写完的不用正则的方式,利用替换后字符长度变化来确认是否包含有子串的变通方式:且支持多行
queue=`sudo -u root postqueue -p` # must runt postqueue by root
echo "queue list under
$queue"
len=${#queue}
mail='_'
mail+=$bName
mail+='@'
mail+=$myDomain
queue=${queue//$mail/'*'}
nLen=${#queue}
echo "$len $nLen
$queue"
------------测试输出,子串都被替换成*号-------------
queue list under
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
BDF9C100576* 3177 Mon Dec 26 15:27:38 MAILER-DAEMON
service_23@myhrd.cn
2202F10057A* 1208 Mon Dec 26 15:27:43 service_23@myhrd.cn
1015488527@qq.com
B8348100475* 1208 Mon Dec 26 15:27:42 service_23@myhrd.cn
1016255977@qq.com
C9D6910048D* 1208 Mon Dec 26 15:27:42 service_23@myhrd.cn
1016261569@qq.com
105A0100531* 1208 Mon Dec 26 15:27:43 service_23@myhrd.cn
1015483425@qq.com
-- 10 Kbytes in 5 Requests.
699 644
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
BDF9C100576* 3177 Mon Dec 26 15:27:38 MAILER-DAEMON
service*
2202F10057A* 1208 Mon Dec 26 15:27:43 service*
1015488527@qq.com
B8348100475* 1208 Mon Dec 26 15:27:42 service*
1016255977@qq.com
C9D6910048D* 1208 Mon Dec 26 15:27:42 service*
1016261569@qq.com
105A0100531* 1208 Mon Dec 26 15:27:43 service*
1015483425@qq.com
-- 10 Kbytes in 5 Requests.