| Author |
How to replace first occurence of a string in another string
|
Ashwin Sridhar
Ranch Hand
Joined: Jul 09, 2011
Posts: 272
|
|
Hi All,
I am trying to read the value from a property file and capture the value into a variable. My property file is a key value pair separted by '=' sign. So in script I replace the values before '=' with empty space and I get the value. Now I have a problem where my value apart also contains '=' sign and when I execute the script my data becomes null. Below is the code i use.
My Property file entry is
Could anyone let me know how to replace only the first occurence of the string?
|
Ashwin Sridhar
SCJP | SCWCD | OCA
|
 |
Richard Tookey
Ranch Hand
Joined: Aug 27, 2012
Posts: 361
|
|
Your expression looks more complex than I would expect but to deal with the immediate problem I think you need to make the second sed expression use a reluctant .* . i.e. 's/^.*?=//' . Does 'sed' allow reluctant qualifiers ? Doesn't seem to !
Edit : Since 'sed' does not seem to support reluctant qualifiers I created a perl version -
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14480
|
|
If I got that correctly:
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
 |
|
|
subject: How to replace first occurence of a string in another string
|
|
|