The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 05-14-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,614
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.
Reply With Quote