Prashast
Prashast

Reputation: 57

Command to find a string and delete it from a file

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

[email protected],[email protected],[email protected] 
[email protected],[email protected],[email protected]
[email protected],[email protected],[email protected]

...and numerous such entries.

I want to find [email protected] and delete it wherever it is present. The output property file (mail.properties) should look like :

[email protected],[email protected] 
[email protected],[email protected]
[email protected],[email protected]

Upvotes: 0

Views: 52

Answers (2)

sat
sat

Reputation: 14949

You can try this sed,

sed 's/[email protected],\?//g; s/,*$//' mail.properties

Use -i option for in-place edit.

sed -i 's/[email protected],\?//g; s/,*$//' mail.properties

Upvotes: 1

keltar
keltar

Reputation: 18399

sed -e 's/bcd_1@gmail\.com//g' -e 's/,,/,/g' -e 's/,$//g' -e 's/=,/=/g' mail.properties > mail.properties_new

Upvotes: 1

Related Questions