I have a full path of a file say hai/hello/home/something/file.txt
.How can I get file.txt
as output eliminating full path?
How to do that with grep?
#!/usr/bin/perl
use File::Spec;
use File::Basename;
$n="hai/hello/home/something/file.txt";
my $m = basename $n;
print "$m";
You don't strictly need grep for this, but if you insist, this should work:
grep -o -e "\w*\.\w*$"
Optionally, consider the command basename:
basename hai/hello/home/something/file.txt