Replacing a string having double slash using sed or awk in linux -


i wish replace

<property name="sourceurl" value="file://d:/uploaded files?move=../../backup&amp;include=.*.ok"/> 

with

<property name="sourceurl" value="file:///tmp/etl-files?move=../../backup&amp;include=.*.ok"/> 

i following approach first find line number , replace line desired text, not happening because of < present @ start of line.

 grep -n  ^<property name="sourceurl" value= etl-job-context.xml 

how can solve this, or there better approach?

you may use sed.

sed 's~\(<property *name="sourceurl" *value="\)[^?]*~\1file:///tmp/etl-files~g' file 

basic sed uses basic regular expression engine matching. in bre \(..\) called capturing group. capture chars exist property tag value parameter. , remaining chars ? matched [^?]*, means match char ?, 0 or more times.

sed uses special chars delimiters. here used ~ because replacement string contains / slashes. \1 in replacement refers chars captured group index 1. , following chars appednded next captured chars. note matched chars automatically removed during replacement.


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 -