Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell egrep需要匹配精确的值,但捕获的内容超出了预期_Shell_Grep - Fatal编程技术网

Shell egrep需要匹配精确的值,但捕获的内容超出了预期

Shell egrep需要匹配精确的值,但捕获的内容超出了预期,shell,grep,Shell,Grep,给定以下代码: for u in `cat /tmp/expiring` ; do /var/tmp/pwx $u egrep [12345] >> /tmp/reallyexpiring done 来自/tmp/expiring的for循环的输入如下所示: bjones password good 25 to expire rsmith password good 3 to expire /tmp/expiring将有几行,都有一个关于帐户将过期多少天的报告,并且每行有一个

给定以下代码:

for u in `cat /tmp/expiring` ; do
  /var/tmp/pwx $u egrep [12345] >> /tmp/reallyexpiring
done
来自/tmp/expiring的for循环的输入如下所示:

bjones password good 25 to expire
rsmith password good 3 to expire
/tmp/expiring将有几行,都有一个关于帐户将过期多少天的报告,并且每行有一个用户

稍后在脚本中,会调用mailx命令来发送电子邮件,但只发送给密码在1到7天内过期的用户

问题是grep语句匹配25天和高于7天阈值的其他值

关于如何修改脚本以仅匹配1 2 3 4 5 6 7的离散值,有什么想法吗?25例如,由于数字25中的2而匹配。

如果您确定空格(或另一个固定字符)将位于数字的前后,则可以执行以下操作

grep " [1-7] "
就你而言

/var/tmp/pwx $u grep " [1-7] " >> /tmp/reallyexpiring
试验
“+[1-7]+”应该这样做,而加号实际上是完成它的空间。非常感谢。
$ cat a
this is 2 and
this is 23 ho
but this is 8
and this 7 is seven

$ grep " [0-7] " a
this is 2 and
and this 7 is seven