[英]Using grep with perl to find files
I am new to perl, and I am currently stuck on this problem. 我是perl的新手,我目前仍在解决此问题。
I was trying something like 我在尝试类似
grep -rl "keyword" /.;
#where does the filenames get stored? let's say in $_?
#foreach valid file, do something
from some website I found, but it doesn't seem to work? 从我发现的某个网站上获取,但似乎不起作用? Help please, Thanks!! 请帮助,谢谢!
How about 怎么样
ls *keyword*
If you trying to do this within perl 如果您尝试在perl中执行此操作
@files = glob("*keyword*");
for $file (@files)
{
print "$file\n";
}
Note that grep
in perl is a core function, but it has nothing to do with regular expressions. 请注意,perl中的grep
是核心功能,但与正则表达式无关。 It is a more like SQL where
; 它更像SQL的where
; it filters an array to a subarray by applying a function (which may or may not be a regex) to each element. 它通过对每个元素应用函数(可能是也可能不是正则表达式)来将数组过滤为子数组。
If glob expressions are not good enough, you can do 如果glob表达式不够好,您可以执行
@files = grep /(fun[kK]y_)keyword?/ glob("*");
perl -E 'say for <*keyword*>'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.