Re: using sed to search third subdirectory from $PWD
From: William Park (opengeometry_at_yahoo.ca)
Date: 12/07/04
- Next message: Dan Mercer: "Re: PID of subshell forked with ()"
- Previous message: Kevin Rodgers: "Re: using sed to search third subdirectory from $PWD"
- In reply to: Tim Gribbin: "using sed to search third subdirectory from $PWD"
- Next in thread: Michael Tosch: "Re: using sed to search third subdirectory from $PWD"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 6 Dec 2004 23:05:19 GMT
Tim Gribbin <tgribbin@buffalo.edu> wrote:
> Hello,
>
> 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:
> /local/sandbox/[username]/project_one/project_one_1/project_one_1_1/...
>
> So I want to set a variable from sed that returns:
>
> /local/sandbox/[username]
>
> 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 <opengeometry@yahoo.ca> Open Geometry Consulting, Toronto, Canada Linux solution for data processing.
- Next message: Dan Mercer: "Re: PID of subshell forked with ()"
- Previous message: Kevin Rodgers: "Re: using sed to search third subdirectory from $PWD"
- In reply to: Tim Gribbin: "using sed to search third subdirectory from $PWD"
- Next in thread: Michael Tosch: "Re: using sed to search third subdirectory from $PWD"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|