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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
regarding replace a part of a string madhu_aqua14 UNIX for Dummies Questions & Answers 7 08-04-2008 11:07 AM
CUT command - cutting characters from end of string JWilliams AIX 2 01-28-2008 09:12 AM
how to get the last part of a string followed by a pattern bluemoon1 Shell Programming and Scripting 4 09-08-2007 12:10 PM
Finding part of a string DAFNIX Shell Programming and Scripting 4 09-21-2006 12:24 AM
Cutting Up a String lesstjm Shell Programming and Scripting 4 09-21-2004 12:40 PM

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 07-25-2005
dhaval_khamar dhaval_khamar is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 2
cutting part of string

Hi,

I wanted to cut a specific portion from given string. How would I do that?
Example:
/u09/core/inbound/abc.txt is my string.
I want abc.txt in a variable.

Please help me.

Regards,
Dhaval
  #2 (permalink)  
Old 07-25-2005
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,960
var=`basename /u09/core/inbound/abc.txt`
echo $var

I believe this question had been answered many times if I am not making assumptions wrongly.
  #3 (permalink)  
Old 07-25-2005
dhaval_khamar dhaval_khamar is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 2
cutting part of string

Hi,

Thanks very much. I tried to search it out from previous messages, but I could not found it.

Best Regards,
Dhaval
  #4 (permalink)  
Old 07-25-2005
Unbeliever Unbeliever is offline
Registered User
  
 

Join Date: Jul 2005
Location: England
Posts: 183
It looks like your strings are paths to files (or directories). If this is always the case the easiest method is to use basename and dirname. eg:

$ dirname /u09/core/inbound/abc.txt
/u09/core/inbound
$ basename /u09/core/inbound/abc.txt
abc.txt

Basically these utilities split and give you everything before and after the last '/' in the string. If your strings are different please qualify.
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 12:01 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