String spllittinf based on pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers String spllittinf based on pattern
# 1  
Old 11-24-2008
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  
Old 11-24-2008
echo "today--RSS_URL=http://someurl" | sed 's/\(.*\)--\(.*\)=\(.*\)/x1=\1\nx2=\2\nx3=\3/'
x1=today
x2=RSS_URL
x3=http://someurl
# 3  
Old 11-24-2008
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  
Old 11-24-2008
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find string based on pattern and search for its corresponding rows in column

Experts, Need your support for this awk script. we have only one input file, all these column 1 and column 2 are in same file and have to do lookup for values in one file(column1 and column2) but output we need in another file Need to grep row whose string contains 9K from column 1. When found... (6 Replies)
Discussion started by: as7951
6 Replies

2. Shell Programming and Scripting

awk to insert missing string based on pattern in file

Using the file below, which will always have the first indicated by the digit after the - and last id in it, indicated by the digit after the -, I am trying to use awk to print the missing line or lines in file following the pattern of the previous line. For example, in the file below the next... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. UNIX for Advanced & Expert Users

Replacing string length based on pattern

Hi All, I have a file which is like below. I need to read all the patterns that starts with P and then replace the 9 digit values to 8 digit values (remove leading integer). Can you please help Example : ( Please look below File) File : P,1 M1,... (7 Replies)
Discussion started by: arunkumar_mca
7 Replies

4. Shell Programming and Scripting

Splitting textfile based on pattern and name new file after pattern

Hi there, I am pretty new to those things, so I couldn't figure out how to solve this, and if it is actually that easy. just found that awk could help:(. so i have a textfile with strings and numbers (originally copy pasted from word, therefore some empty cells) in the following structure: SC... (9 Replies)
Discussion started by: luja
9 Replies

5. UNIX for Dummies Questions & Answers

Find next line based on pattern, if it is similar pattern skip it

Hi, I am able to get next line if it is matching a particular pattern. But i need a way to skip if next line also matches same pattern.. For example: No Records No Records Records found got it Records found Now i want to find 'Records found' after 'No Records' pattern matches.. ... (5 Replies)
Discussion started by: nagpa531
5 Replies

6. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

7. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

8. Shell Programming and Scripting

Print a pattern between the xml tags based on a search pattern

Hi all, I am trying to extract the values ( text between the xml tags) based on the Order Number. here is the sample input <?xml version="1.0" encoding="UTF-8"?> <NJCustomer> <Header> <MessageIdentifier>Y504173382</MessageIdentifier> ... (13 Replies)
Discussion started by: oky
13 Replies

9. Shell Programming and Scripting

Concatenating and appending string based on specific pattern match

Input #GEO-1-type-1-fwd-Initial 890 1519 OPKHIJEFVTEFVHIJEFVOPKHIJTOPKEFVHIJTEFVOPKOPKHIJHIJHIJTTOPKHIJHIJEFVEFVOPKHIJOPKHIJOPKEFVEFVOPKHIJHIJEFVHIJHIJEFVTHIJOPKOPKTEFVEFVEFVOPKHIJOPKOPKHIJTTEFVEFVTEFV #GEO-1-type-2-fwd-Terminal 1572 2030... (7 Replies)
Discussion started by: patrick87
7 Replies

10. Shell Programming and Scripting

Retrieve string from each line in a file based on a pattern in Unix

I have a file which contains several lines. Sample content of the file is as below. OK testmessage email<test@123> NOK receivemessage email<123@test> NOK receivemessage email(123@test123) NOK receivemessage email<abc@test> i would like to know by scripting will... (10 Replies)
Discussion started by: ramasar
10 Replies
Login or Register to Ask a Question