Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Removing characters from value

 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried 'cut'?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
eg
echo my.txt|cut -d. -f1 -
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know the extension in advance, you can also use the 'basename' command.
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for reply.

DOM, you trick is working now.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but inly if there is a single '.' in the file name. Buyer beware
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can try:



or


[ July 03, 2007: Message edited by: Craig Jackson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic