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
Was it helpful?

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

OTHER TIPS

sed -e 's/bcd_1@gmail\.com//g' -e 's/,,/,/g' -e 's/,$//g' -e 's/=,/=/g' mail.properties > mail.properties_new
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top