grep 正则表达式选项要记得转义
- font size decrease font size increase font size
- Print Email
使用过程中,使用最多的参数就是 -v ,但是用着并不爽。
比如说,我想查找一个单词“UserService”,但是像”*.svn” 这种文件就不用显示了,我该怎么做呢?
grep -r "UserService" ./ | grep -v "svn"
但是,如果类似于含有”test、auto_load”之类的文件我也不显示,怎么做呢?我之前的做法是:
grep -r "UserService" ./ | grep -v "svn" | grep -v "test" | grep -v "auto_load"
命令很长,而且麻烦,于是就想,grep本身是按照正则表达式来当做选项的,那么我是不是可以利用到正则表达式的“或|”命令?
grep -r "UserService" ./ | grep -v "svn|test|auto_load"
很显示,执行结果显示上面的命令不符合我的需求,于是苦思不得其解。原来,在使用正则表达式选项时,要记得将”|”转义。最终命令如下:
grep -r "UserService" ./ | grep -v "svn\|prj\|test\|auto_load"
( ! ) Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 169 | ||||
---|---|---|---|---|
Call Stack | ||||
# | Time | Memory | Function | Location |
1 | 0.0007 | 412408 | {main}( ) | .../index.php:0 |
2 | 0.0794 | 4262680 | Joomla\CMS\Application\SiteApplication->execute( ) | .../index.php:49 |
3 | 0.0794 | 4262680 | Joomla\CMS\Application\SiteApplication->doExecute( ) | .../CMSApplication.php:196 |
4 | 0.3187 | 11453744 | Joomla\CMS\Application\SiteApplication->dispatch( ) | .../SiteApplication.php:233 |
5 | 0.3212 | 11478344 | Joomla\CMS\Component\ComponentHelper::renderComponent( ) | .../SiteApplication.php:194 |
6 | 0.3235 | 11533672 | Joomla\CMS\Component\ComponentHelper::executeComponent( ) | .../ComponentHelper.php:377 |
7 | 0.3241 | 11561072 | require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ) | .../ComponentHelper.php:402 |
8 | 0.3410 | 11960704 | K2ControllerItem->execute( ) | .../k2.php:64 |
9 | 0.3410 | 11960704 | K2ControllerItem->display( ) | .../BaseController.php:710 |
10 | 0.3571 | 12611408 | K2ControllerItem->display( ) | .../item.php:78 |
11 | 0.3571 | 12611408 | K2ControllerItem->display( ) | .../controller.php:19 |
12 | 0.3637 | 12982448 | Joomla\CMS\Cache\Controller\ViewController->get( ) | .../BaseController.php:663 |
13 | 0.3691 | 13002816 | K2ViewItem->display( ) | .../ViewController.php:102 |
14 | 0.4758 | 15850920 | K2ViewItem->display( ) | .../view.html.php:742 |
15 | 0.4759 | 15850920 | K2ViewItem->loadTemplate( ) | .../HtmlView.php:230 |
16 | 0.4786 | 16023856 | include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ) | .../HtmlView.php:701 |
- Published in CentOS 6
- Read 2882 times
( ! ) Notice: Only variables should be assigned by reference in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 478 | ||||
---|---|---|---|---|
Call Stack | ||||
# | Time | Memory | Function | Location |
1 | 0.0007 | 412408 | {main}( ) | .../index.php:0 |
2 | 0.0794 | 4262680 | Joomla\CMS\Application\SiteApplication->execute( ) | .../index.php:49 |
3 | 0.0794 | 4262680 | Joomla\CMS\Application\SiteApplication->doExecute( ) | .../CMSApplication.php:196 |
4 | 0.3187 | 11453744 | Joomla\CMS\Application\SiteApplication->dispatch( ) | .../SiteApplication.php:233 |
5 | 0.3212 | 11478344 | Joomla\CMS\Component\ComponentHelper::renderComponent( ) | .../SiteApplication.php:194 |
6 | 0.3235 | 11533672 | Joomla\CMS\Component\ComponentHelper::executeComponent( ) | .../ComponentHelper.php:377 |
7 | 0.3241 | 11561072 | require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ) | .../ComponentHelper.php:402 |
8 | 0.3410 | 11960704 | K2ControllerItem->execute( ) | .../k2.php:64 |
9 | 0.3410 | 11960704 | K2ControllerItem->display( ) | .../BaseController.php:710 |
10 | 0.3571 | 12611408 | K2ControllerItem->display( ) | .../item.php:78 |
11 | 0.3571 | 12611408 | K2ControllerItem->display( ) | .../controller.php:19 |
12 | 0.3637 | 12982448 | Joomla\CMS\Cache\Controller\ViewController->get( ) | .../BaseController.php:663 |
13 | 0.3691 | 13002816 | K2ViewItem->display( ) | .../ViewController.php:102 |
14 | 0.4758 | 15850920 | K2ViewItem->display( ) | .../view.html.php:742 |
15 | 0.4759 | 15850920 | K2ViewItem->loadTemplate( ) | .../HtmlView.php:230 |
16 | 0.4786 | 16023856 | include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ) | .../HtmlView.php:701 |