The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 12:14 PM
Parse String from a Variable racbern Shell Programming and Scripting 3 04-07-2008 12:04 PM
how to parse this string hcliff Shell Programming and Scripting 13 04-02-2008 04:43 AM
String parse question mnreferee Shell Programming and Scripting 5 03-07-2007 12:30 AM
parse variable mpang_ Shell Programming and Scripting 2 01-03-2007 07:31 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-18-2005
methos methos is offline
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.
  #2 (permalink)  
Old 10-18-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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)
  #3 (permalink)  
Old 10-18-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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)
  #4 (permalink)  
Old 10-18-2005
methos methos is offline
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.
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 05:32 AM.


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