Question

I have a property file mail.properties. The content of the file is

ErrorEmailTo.server1=abc_1@gmail.com,bcd_1@gmail.com,efg_1@gmail.com 
ErrorEmailFrom.server1=abc_1@gmail.com,bcd_1@gmail.com,efg_1@gmail.com
ErrorEmailCC.server1=abc_1@gmail.com,efg_1@gmail.com,bcd_1@gmail.com

...and numerous such entries.

I want to find bcd_1@gmail.com and delete it wherever it is present. The output property file (mail.properties) should look like :

ErrorEmailTo.server1=abc_1@gmail.com,efg_1@gmail.com 
ErrorEmailFrom.server1=abc_1@gmail.com,efg_1@gmail.com
ErrorEmailCC.server1=abc_1@gmail.com,efg_1@gmail.com
Était-ce utile?

La solution

You can try this sed,

sed 's/bcd_1@gmail.com,\?//g; s/,*$//' mail.properties

Use -i option for in-place edit.

sed -i 's/bcd_1@gmail.com,\?//g; s/,*$//' mail.properties

Autres conseils

sed -e 's/bcd_1@gmail\.com//g' -e 's/,,/,/g' -e 's/,$//g' -e 's/=,/=/g' mail.properties > mail.properties_new
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top