• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to replace first occurence of a string in another string

 
Ashwin Sridhar
Ranch Hand
Posts: 277
Flex Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18100
51
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I got that correctly:

 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic