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
Listing filesnames in bare format with fullpath tipsy Shell Programming and Scripting 2 01-26-2007 05:17 PM
extracting only the filename without its extenstion lotus123 UNIX for Dummies Questions & Answers 3 08-25-2005 11:44 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 04-19-2007
njoshi njoshi is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 6
Extracting Filename from Fullpath

Hi,
Any help on this would be very appreciated.

I capture the full path & filename in a variable like (varFile=/home/user/extfile.txt). Now in my shell script I have to use only the filename part i.e. extfile.txt. How do I extract only the filename part from the variable?

Thanks in Advance.
  #2 (permalink)  
Old 04-19-2007
awk awk is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
see basename or dirname
  #3 (permalink)  
Old 04-19-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by njoshi
Hi,
Any help on this would be very appreciated.

I capture the full path & filename in a variable like (varFile=/home/user/extfile.txt). Now in my shell script I have to use only the filename part i.e. extfile.txt. How do I extract only the filename part from the variable?

Use shell parameter expansion:

Code:
filename=${varFile##*/}
  #4 (permalink)  
Old 04-19-2007
njoshi njoshi is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 6
Thanks a lot. That helps.
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 07:40 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