Re: using sed to search third subdirectory from $PWD
From: William Park (opengeometry_at_yahoo.ca)
Date: 6 Dec 2004 23:05:19 GMT
Tim Gribbin <email@example.com> wrote:
> I'm trying to use sed and $PWD to find a directory path from the third
> directory back, and the third directory name will vary. There can be
> any number of subdirectories beyond the third.
> For example, $PWD would produce something like this:
> So I want to set a variable from sed that returns:
> Note that the username may not necessarily be the logged in user.
> I'm not quite sure how to get at that third directory since I don't know
> what the value will be.
> I started with something like the below, but obviously this is
> inadequate since I really need to grab that third directory and back,
> but I'm not sure how to isolate the third directory. The code below
> returns all directories but I'm not sure how to limit it.
> set local_path = `echo $PWD | sed 's:/local/sandbox/*/:/local/sandbox/:'`
> Thanks in advance for any help!
> Tim Gribbin
Assuming it's always absolute path (with leading /),
echo ... | cut -f1-4 -d/
-- William Park <firstname.lastname@example.org> Open Geometry Consulting, Toronto, Canada Linux solution for data processing.