The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > AIX
Google UNIX.COM


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Add string after another string with special characters heliode Shell Programming and Scripting 2 03-21-2008 05:06 AM
cutting part of string dhaval_khamar Shell Programming and Scripting 3 07-25-2005 07:18 AM
Cutting Up a String lesstjm Shell Programming and Scripting 4 09-21-2004 08:40 AM
Removing characters from end of $string craig2k Shell Programming and Scripting 3 03-25-2003 07:38 AM
removing characters from end of string el_toro Shell Programming and Scripting 4 07-14-2002 05:02 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-21-2008
Registered User
 

Join Date: Apr 2007
Posts: 9
CUT command - cutting characters from end of string

Hello,

I need to delete the final few characters from a parameter leaving just the first few. However, the characters which need to remain will not always be a string of the same length.

For instance, the parameter will be passed as BN_HSBC_NTRS/hub_mth_ifce.sf. I only need the bit before the slash - BN_HSBC_NTRS. However, this could also be passed as BN_HUB_NTRS/hub_mth_ifce.sf - slightly shorter. Is there a way of removing the /hub_mth_ifce.sf part and storing it as an additional parameter?

Thanks,

John.
Reply With Quote
Forum Sponsor
  #2  
Old 01-21-2008
salaathi's Avatar
Registered User
 

Join Date: Sep 2007
Location: Madurai
Posts: 20
use awk -F

awk -F/ ' {print $1}' filename > outputfile
Reply With Quote
  #3  
Old 01-28-2008
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,235
Look at the "dirname" and "basename" commands, they should suit you.

Another possibility would be to use the "${var%%/*}" shell expansion:

Code:
myvar="abcde/1234"
print - ${myvar%%/*}           # will produce "abcde"
If your variable contains more than one "/" use the single or the double percent-sign depending on what you want to get:

Code:
myvar="abcde/1234/xyz"
print - ${myvar%%/*}           # will produce "abcde"
print - ${myvar%/*}            # will produce "abcde/1234"
bakunin
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:47 PM.


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