aspose file tools*
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: 3636
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: 16014
    
  20

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


Customer surveys are for companies who didn't pay proper attention to begin with.
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
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 ]
 
Consider Paul's rocket mass heater.
 
subject: Removing characters from value