How to extract filename from the path; i have a list of files. I'm using csh shell, and have awk, sed, perl installed.
/dfgfd/dfgdfg/filename
should give me
filename
I tried basename:
find $PROJDIR -name '*.c' -o -name '*.cc' -o -name '*.h'
| xargs grep -l pattern | xargs basename
and it gave me the following error:
basename: too few arguments Try `basename --help' for more information.
thx
The standard program basename
does what you want:
$ basename /dfgfd/dfgdfg/filename
filename
This kind of workaround worked for me. You said you had perl so this should run. It replaces all nonspace text up to the last / with nothing (effectively deleting it).
find $PROJDIR -name '*.c' -o -name '*.cc' -o -name '*.h'
| xargs grep -l pattern | perl -pi -e "s/\S+\///g"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With