Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Posts
    43

    Unanswered: remove path from find results

    I want to use the find command in a shell script to create list all image files in a directory, the current line in my code is:

    find $TEMP_DIR/ -name "*.tif" > $LOAD_FILE

    which produces a file like:

    /dir1/dir2/dir3/test1.tif
    /dir1/dir2/dir3/test2.tif
    /dir1/dir2/dir3/test3.tif

    How can I remove the directory path so the file only contains a list of tif files.

    Any help would be appreciated as you can probably tell I am no UNIX expert.

    Cheers.

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    Code:
    find $TEMP_DIR/ -name "*.tif" | sed 's!.*/!!' > $LOAD_FILE
    sed 's!.*/!!' => replace (s) all chars until last / (.*/) by nothing ()
    Jean-Pierre.

  3. #3
    Join Date
    Oct 2003
    Posts
    43
    Thanks that worked a treat!

  4. #4
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    You could also do this using find's 'exec' option...

    find "$TEMP_DIR" -name "*.tif" -exec basename {} \;

    Damian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •