Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help: find command need to display only name of the file 2

Status
Not open for further replies.

annanathan

Programmer
May 1, 2002
24
0
0
CA
Hi all,

I need help to understand how to use the find command to get the name of the file only.
Code:
find d:/something/ -name "*.txt" -exec another_script.sh {} \ ;

I need to pass only the name of the file found in the 'another_script.sh'. (extenstion excluded also)

Thank you in advance...
Any help is appreciated.
 
Hi:

I'm not exactly certain what you want to do. The find command you've posted says to search the d:/something directory for every object with a ".txt" extension and call script another_script.sh.

I'm assuming (?) you want each file going to this script to have only the name. If that's the case, use the basename command. Place basename $1

as the first line in another_script.sh?

Regards,


Ed
 
HI Ed,
The $1 gives me the full path with the name of the file found: eg d:/something/name_of_file.txt

I just need 'name_of_file' to show... eliminating the path and the extension.

Thank you in advance.

Jey
 
Jey:

How about this as the first line in another_script.sh:

file=`basename $1|cut -f1 -d "."`

cut out just the first field where the delimiter is "."?

Regards,


Ed
 
Thank you very much...
This is exactly what I was looking for...

Regards,
Jeya
 
The basename command can remove the extension if you know it:
Code:
file=`basename  $1  .txt`
 
dchoulette:

I know this thread is old, but I'm behind on my reading. I did not know you could do this with basename. Guess I should be reading the man pages closer.

Thanks!

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top