wood burning stoves 2.0
The moose likes Linux / UNIX and the fly likes Removing characters from value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Removing characters from value" Watch "Removing characters from value" New topic
Author

Removing characters from value

Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
Want to search for a particular file in folder and need the name of the found file without extension.

eg:
I am looking for a file nameed *_chetan.xls, so I will fire following command

ls *_chetan.xls

Suppose about command returns 20070628_chetan.xls, I need to remove .xls from that value.

FILE_NAME=`ls *_Target.xls` command will return filename. How to remove extension from the result?


My blood is tested +ve for Java.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Have you tried 'cut'?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

eg
echo my.txt|cut -d. -f1 -
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17145
    
  27

If you know the extension in advance, you can also use the 'basename' command.


An IDE is no substitute for an Intelligent Developer.
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3640
Thanks all for reply.

DOM, you trick is working now.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

but inly if there is a single '.' in the file name. Buyer beware
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Or you can try:



or


[ July 03, 2007: Message edited by: Craig Jackson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Removing characters from value
 
It's not a secret anymore!