|
grep normally returns the entire matching line anyway.
The regular expression should work with grep as such, if you make a few minor substitutions. \d is a Perlism, replace with [0-9]. {4} is an egrep-ism, although POSIX grep has it in some form, too (maybe with backslashes before the braces); or you can simply put the required number of repetitions.
You will be hard pressed to find a situation where you can get exactly only the required parts out of grep, though. [0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9] and [^/]*$ will still work, but the penultimate directory I don't think you can get without passing through sed or some such.
|