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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep for a pattern based on another patter rock1 UNIX for Dummies Questions & Answers 7 10-18-2008 05:32 PM
Truncating FILE data BASED ON A PATTERN pkumar3 Shell Programming and Scripting 1 10-14-2008 11:49 AM
how to change a particular value in a file based on a pattern orbeyen UNIX for Dummies Questions & Answers 9 08-20-2008 03:09 AM
appending with sed based on matched pattern jack1981 Shell Programming and Scripting 2 07-20-2006 06:54 AM
appending string to text file based on search string malaymaru Shell Programming and Scripting 1 06-09-2006 08:53 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 11-24-2008
eswarreddya eswarreddya is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 5
String spllittinf based on pattern

Hi,

I have a sample.properties file and it contains the following content.

today--RSS_URL=http://someurl


i need to split the string and need the result in the folliwng form.

x1=today
x2=RSS_URL
x3=http://someurl


Your immediate response will be graetly appreciated
  #2 (permalink)  
Old 11-24-2008
Konerak Konerak is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 20
echo "today--RSS_URL=http://someurl" | sed 's/\(.*\)--\(.*\)=\(.*\)/x1=\1\nx2=\2\nx3=\3/'
x1=today
x2=RSS_URL
x3=http://someurl
  #3 (permalink)  
Old 11-24-2008
eswarreddya eswarreddya is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 5
Thanks Koneark,

but i have one more prob here.
when i run
echo "today--RSS_URL=http://someurl" | sed 's/\(.*\)--\(.*\)=\(.*\)/x1=\1\nx2=\2\nx3=\3/'

it is giving the out as below.

x1=todaynx2=RSS_URLnx3=http://someurl



But I need the out put as

x1=today
x2=RSS_URL
x3=http://someurl

and i need to export these x1, x2 and x3 to the shell.

Thanks,
Eswar
  #4 (permalink)  
Old 11-24-2008
Konerak Konerak is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 20
Code:
#!/bin/sh

var='today--RSS_URL=http://someurl'

x1=`echo $var | sed "s_\(.*\)--\(.*\)=\(.*\)_\1_"`
x2=`echo $var | sed "s_\(.*\)--\(.*\)=\(.*\)_\2_"`
x3=`echo $var | sed "s_\(.*\)--\(.*\)=\(.*\)_\3_"`

echo "Testing results: var($var) x1($x1) x2($x2) x3($x3)"
This script will set the variables as you wish. You can export them or modify them or do whatever you want with them then.
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

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:11 PM.


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