If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > remove path from find results

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-25-04, 04:38
chumpski chumpski is offline
Registered User
 
Join Date: Oct 2003
Posts: 43
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.
Reply With Quote
  #2 (permalink)  
Old 02-25-04, 04:58
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
Code:
find $TEMP_DIR/ -name "*.tif" | sed 's!.*/!!' > $LOAD_FILE
sed 's!.*/!!' => replace (s) all chars until last / (.*/) by nothing ()
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 02-25-04, 05:04
chumpski chumpski is offline
Registered User
 
Join Date: Oct 2003
Posts: 43
Thanks that worked a treat!
Reply With Quote
  #4 (permalink)  
Old 02-25-04, 05:33
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On