![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
use awk -F
awk -F/ ' {print $1}' filename > outputfile
|
|
#3
|
|||
|
|||
|
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"
Code:
myvar="abcde/1234/xyz"
print - ${myvar%%/*} # will produce "abcde"
print - ${myvar%/*} # will produce "abcde/1234"
|
|||
| Google The UNIX and Linux Forums |