matching paths 
Author Message
 matching paths

Using the following example paths
1) /proj/test/user
2) /proj/temp/proj/neil/test
3) /u/neil/proj/test

We have been trying to create a command line script that would :
pwd | gawk and then return to us everyting before the last occurance of
proj

Examples from above would output
1) /
2) /proj/temp
3) /u/neil

Anyhelp is appreciated

Neil



Tue, 09 Dec 2003 03:27:16 GMT  
 matching paths
Hi Neil,

   A single line of sed should do it:

pwd | sed -e 's/\(.\{1,\}\)proj.*/\1/'|sed -e 's/\(.\{1,\}\)\//\1/'

Regards
Raman

Quote:

> Using the following example paths
> 1) /proj/test/user
> 2) /proj/temp/proj/neil/test
> 3) /u/neil/proj/test

> We have been trying to create a command line script that would :
> pwd | gawk and then return to us everyting before the last occurance of
> proj

> Examples from above would output
> 1) /
> 2) /proj/temp
> 3) /u/neil

> Anyhelp is appreciated

> Neil




Tue, 09 Dec 2003 04:13:38 GMT  
 matching paths


Quote:
>Using the following example paths
>1) /proj/test/user
>2) /proj/temp/proj/neil/test
>3) /u/neil/proj/test

>We have been trying to create a command line script that would :
>pwd | gawk and then return to us everyting before the last occurance of
>proj

>Examples from above would output
>1) /
>2) /proj/temp
>3) /u/neil

awk 'BEGIN{FS=OFS="proj"} {$NF="";NF-=1;print}'

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 09 Dec 2003 04:34:53 GMT  
 matching paths
Works like a charm

Thanks
Neil

Quote:



> >Using the following example paths
> >1) /proj/test/user
> >2) /proj/temp/proj/neil/test
> >3) /u/neil/proj/test

> >We have been trying to create a command line script that would :
> >pwd | gawk and then return to us everyting before the last occurance of
> >proj

> >Examples from above would output
> >1) /
> >2) /proj/temp
> >3) /u/neil

> awk 'BEGIN{FS=OFS="proj"} {$NF="";NF-=1;print}'

> Chuck Demas

> --
>   Eat Healthy    |   _ _   | Nothing would be done at all,

>   Die Anyway     |    v    | That no one could find fault with it.




Tue, 09 Dec 2003 05:03:17 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. REPOST: Re: import path, script path (was Re: module path)

2. match works, don't match doesn't

3. iss-matching - the free Regular Expression / Pattern Matching cluster

4. to match and not to match

5. how to do exact match for all characters using re.match()

6. String Match - not matching

7. re.match(...) fails to find a match

8. regexp matching to shortest instead of longest match?

9. C4 PATH() returns WRONG PATH in Win95!

10. Making file path control only select directory paths not file names

11. how do I set path or add path

12. how to translate a virtual path to a physical path in a CGI script

 

 
Powered by phpBB® Forum Software