与grep匹配的模式
这个问题在这里已经有了答案:
#!/usr/bin/perl
use File::Spec;
use File::Basename;
$n="hai/hello/home/something/file.txt";
my $m = basename $n;
print "$m";
你不必严格要求grep,但如果你坚持,这应该工作:
grep -o -e "w*.w*$"
或者,请考虑命令基本名称:
basename hai/hello/home/something/file.txt
你可以用sed
来做:
$ echo hai/hello/home/something/file.txt | sed "s|.*/||g"
file.txt
或者更简单的, basename
:
$ basename hai/hello/home/something/file.txt
file.txt
链接地址: http://www.djcxy.com/p/57089.html
上一篇: Pattern matching with grep
下一篇: how to delete filename's specific suffix in a dir, in linux