Hi,
I am trying to get a file name only. Could anyone help me on the same.
Meaning I have a file say list.out which holds below output
./xyz/abc.txt
./xyz/hij.txt
I want an output as below
abc.txt
hij.txt
i.e I want to delete everything before abc.txt
Please help me out if any one has the ans.
Please use a more useful title next time. This cannot possibly be that urgent - i.e., your system will not crash if you don't know how to do this.
The command you want is basename
>echo basename /path/to/file/file.txt
file.txt
>
xargs -n1 < list.out basename
abc.txt
hij.txt
cat list.out | awk -F "/" '{print $3}'
Awk is incredibly much faster (more noticeable for larger list.out files) - and handles filenames with spaces, but I'd change it slightly
awk -F/ '{print $NF}' list.out
0.05 seconds for 8000+ files, versus 6.3 seconds using xargs.
(not that I'm a fan of the UUOC club - it took the same time with or without cat!)
It's even quicker than sed (0.09 seconds)
sed "s+.*/++" list.out