The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
extracting date from a filename laiko UNIX for Dummies Questions & Answers 7 11-25-2008 03:24 PM
mv Filename variable to another filename gzs553 Shell Programming and Scripting 3 04-14-2008 05:19 PM
shortcut for tar cvf - [filename] | gzip > [filename].tar.gz bcamp1973 UNIX for Dummies Questions & Answers 4 12-11-2007 05:45 PM
Extracting Filename from Fullpath njoshi UNIX for Dummies Questions & Answers 3 04-19-2007 06:34 PM
extracting from tar.bz2 Raom UNIX for Advanced & Expert Users 1 03-07-2006 10:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2005
lotus123 lotus123 is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 3
extracting only the filename without its extenstion

Hi,

I have a requirement that i need to store only the filename without its extension. Can anyone please help me to do this.

For Example, i have stored the filename in a varialble called fname. I need to extract all the charecters before the first occurence of the dot.
If fname has value as PG_0008_20050519.xml.gz then i need to extract only "PG_0008_20050519". Please help me to do this.

TIA.
  #2 (permalink)  
Old 08-24-2005
98_1LE 98_1LE is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2000
Location: Greater Dallas area
Posts: 405
If the extension is always the same:

Code:
fname=`basename $fname xml.gz`

If the extension is not always the same:

Code:
fname=`echo $fname | cut -d\. -f1`
fname=${fname}.

  #3 (permalink)  
Old 08-24-2005
lotus123 lotus123 is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 3
Works Perfect.

Thanks a lot for the help.
  #4 (permalink)  
Old 08-25-2005
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
some more ways

the first is one with awk
echo `basename <program-path>` | awk -F"." '{print $1}'

this one is with sed but no of characters in extension need to be known in prior
for 3 character extension
echo `basename <program-path>` | sed -e 's/\....//'

advancement to the above method, no of characters in extension need not be known

echo `basename <program-path>` | sed -e 's/\..*//'
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0