2013-08-19 34 views
0

如何将这些行与UNIX的grep匹配?Grep通配符在中间

call($variable, 'tiki-index.php'); 
call('string123', 'tiki-index.php'); 
call(13, 'tiki-index.php'); 

我试图

[email protected]:~$ grep -e "smarty->assign(*, 'tiki-index.php');" . 

但命令匹配以上皆非。

回答

0

你的模式grep -e "smarty->assign(*, 'tiki-index.php');"将匹配如下:

smarty->assign(, 'tiki-index.php'); 
smarty->assign((, 'tiki-index.php'); 
smarty->assign(((, 'tiki-index.php'); 
... 

(即*适用于(。)

您想指定任何字符,即.,然后匹配*它的实例。使用方法:

grep -e "smarty->assign(.*, 'tiki-index.php');" 

改为。

1

使用-R进行搜索递归。 如果您不希望搜索是递归的,请在*上搜索而不搜索。

而你需要你的正则表达式更改为:

"call(.*, 'tiki-index.php');" 

,或者使用Smarty:

"smarty\->assign(.*, 'tiki-index.php');" 

有关更多信息,正则表达式查看文档。

1

我有以下文件

cat x.txt 
call($variable, 'tiki-index.php'); 
call('string123', 'tiki-index.php'); 
call(13, 'tiki-index.php'); 
call(sdfadf..df.d.foo); 
small(12, 'tiki-index.php'); 

我grep的回报之后,你可以把它作为特定的或一般的,只要你想

grep -e "call.*\'tiki-index.php\');" x.txt 
call($variable, 'tiki-index.php'); 
call('string123', 'tiki-index.php'); 
call(13, 'tiki-index.php');