The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Parse String Using Sed racbern Shell Programming and Scripting 4 04-23-2008 09:14 AM
Parse String from a Variable racbern Shell Programming and Scripting 3 04-07-2008 09:04 AM
how to parse this string hcliff Shell Programming and Scripting 13 04-02-2008 01:43 AM
String parse question mnreferee Shell Programming and Scripting 5 03-06-2007 09:30 PM
parse variable mpang_ Shell Programming and Scripting 2 01-03-2007 04:31 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-18-2005
Registered User
 

Join Date: Jan 2002
Posts: 18
parse a string variable

Hello all, need a little help.

I have an input variable such as ARGV[0] which equals something like

/use/home/name/script/test.dat

I need to be able to get just the "test.dat" (i.e. the file name) at the end of the directory and the directory can be anything and any length. To put it another way, I want the value after the last "/".

Thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 10-18-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Are you in shell? If so basename will return the name of the file minus the path.

The arguments to shell are referenced by $1 $2 $3 .....

In C there is a function char *basename(char *path_and_file)
Reply With Quote
  #3  
Old 10-18-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
It just occurred to me that you must be in a perl script.... try something along these lines
Code:
use Shell qw(basename);
..........
........
$base=basename($file)
Reply With Quote
  #4  
Old 10-18-2005
Registered User
 

Join Date: Jan 2002
Posts: 18
basename worked great! Thanks a ton. After gave me the direction (ie answer) I found that basename is both a PERL and a Unix command.

Thanks again for the quick response.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0