So say I have a list of files in a text file:
...
/foo/barfoo
/bar/foo/foobar
/foobar/bar/foo
...
I have a script that will search through this text file and, much like the locate command, I want to be able to search for the basename of the file. Thus far I've used this grep command grep -E */.*${1}[^/]*$
which works fine UNLESS I want to grep for a regex. So, in the above example if I wanted to find files starting with "foo", I'd execute myscript --basename ^foo
however this fails because the whole regex becomes grep -E */.*^foo[^/]*$
which would, obviously, fail. I thought about using xargs to plug each entry into basename but I need the script to put out the whole file path at the end.
Any ideas? I'd prefer POSIX compliance but GNUisms are fine too