Find the first occurence of file in pwd with sed 
Author Message
 Find the first occurence of file in pwd with sed

Hi,

I'm not sure that this is the good news group for this
question , if not, does anybody knows where i can post my question

my question:

Is there any way with sed to find the first
location of a file (in my case build.xml for ant) in a "backward search"
on $PWD (and if there is not occurrence of this file in parent
directory  or in the parent directory of the parent directory or
... or in /. then sed return $PWD)?

(This is probably very simple but I'am not an sed expert)

Thanks,
Guillaume

--
Guillaume Riviere
ObjectWeb Consortium    



Sat, 21 Aug 2004 22:32:18 GMT  
 Find the first occurence of file in pwd with sed


X Hi,
X
X I'm not sure that this is the good news group for this
X question , if not, does anybody knows where i can post my question
X
X my question:
X
X Is there any way with sed to find the first
X location of a file (in my case build.xml for ant) in a "backward search"
X on $PWD (and if there is not occurrence of this file in parent
X directory  or in the parent directory of the parent directory or
X ... or in /. then sed return $PWD)?
X
X (This is probably very simple but I'am not an sed expert)
X
X
X Thanks,
X Guillaume

I'm not much of a sed person, but with sh (or similar bourne shell
decendent) you could try:

        path=`pwd`
        while [ $path != / ]
        do
                if [ -e $path/build.xml ]; then
                        break;
                fi
                path=`dirname $path`
        done
        if [ $path = / ]; then
                path=`pwd`
        fi

I'm assumnig that you are on a UNIX system.  If my assumptions are
wrong, then please accept my apology.

                                        Bob Harris



Sun, 22 Aug 2004 06:41:09 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Find last occurence of regular expression

2. Finding first instance of string in multiple files

3. Re module pwd not found in pythonwin

4. FIND FIRST, FIND NEXT

5. Sed: Inserting file in another file

6. sed: input file = output file

7. pwd on nt/95: why return C://file...?

8. help on sed file

9. log file processing - awk or sed

10. Using awk And/Or sed To Edit Fourth Field Of File

11. sed - extracting "*.cpp" from a file

12. SED multiple file redirection?

 

 
Powered by phpBB® Forum Software