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
Spliting file based on condition Raamc Shell Programming and Scripting 2 05-15-2008 12:51 PM
searching and storing unknown number of lines based on the string with a condition swamymns Shell Programming and Scripting 7 05-13-2008 02:02 AM
command for deleting log files based on some condition pulkit Shell Programming and Scripting 4 01-09-2008 06:17 AM
Read file based on condition sbasetty Shell Programming and Scripting 5 02-01-2007 02:54 AM
awk script to split a file based on the condition superprogrammer Shell Programming and Scripting 12 06-14-2005 04:59 AM

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 03-19-2008
sankar reddy sankar reddy is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 6
How to split the String based on condition?

hi ,
I have a String str="/opt/ibm/lotus/ibw/latest" or ="/opt/lotus/ibw/latest" this value is dynamic..I want to split this string into 2 strings

1. /opt/ibm/lotus(/opt/lotus) this string must ends with "lotus"
2./ibw/latest

can any body help me on this?

Regards,
sankar
  #2 (permalink)  
Old 03-19-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,892
For the first part use this:

Code:
"${str%${str#*lotus}}"
for the second this:

Code:
"${str#*lotus}"
  #3 (permalink)  
Old 03-19-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,315
Or with sed:

Code:
echo "/opt/ibm/lotus/ibw/latest" | sed 's!\(.*lotus\).*!\1!'
gives: /opt/ibm/lotus

Code:
echo "/opt/ibm/lotus/ibw/latest" | sed 's!.*lotus\(.*\)!\1!'
gives: /ibw/latest


Regards
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:10 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