parsing - How do I replace a string between a set of delimiter strings including the second delimiter with sed? -


how replace string between set of delimiter strings sed? first delimiter string not replaced while; second delimiter single char needs replaced part of replacement.

i.e.

first_delem="getval("  second_delem=”,” example string: abc = param.getval((m_astringtoreplace, xml_somedata, stringparameter(l"")); 

the string replace or remove = (m_astringtoreplace,

this following sed command parse out string, not replace it.

sed -e 's/.*getval(\(.*\),.*/\1/' 

how use sed replace string using these complex delimiters ?

with input:

$ cat file abc = param.getval((m_astringtoreplace, xml_somedata, stringparameter(l"")); 

this performs replacement of string starts following getval( , ends first comma:

$ sed -re 's/(getval[(])[^,]*,/\1replacement/' file abc = param.getval(replacement xml_somedata, stringparameter(l"")); 

the regex (getval[(]) captures first delimiter group 1. [^,]*, matches follows , including first comma, ,.

note that, if had used .*, in place of [^,]*,, have matched last comma in string.

in replacement part of substitution, \1 restores first delimiter, 1 wanted keep. follows replacement, whatever want be.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -