Operating System - HP-UX
1827720 Members
3207 Online
109968 Solutions
New Discussion

Re: sed command to replace string

 
SOLVED
Go to solution
panchpan
Regular Advisor

sed command to replace string

Hello.
I grepped certain pattern and got below results:
WSS_80_err.mail:xyz@abb.com
WSS_81_err.mail:xyz@abb.com
WSS_82_err.mail:xyz@abb.com
WSS_83_err.mail:xyz@abb.com
WSS_ERR_80.mail:xyz@abb.com
WSS_ERR_81.mail:xyz@abb.com
WSS_ERR_82.mail:xyz@abb.com
WSS_ERR_83.mail:xyz@abb.com

Now I wish to replace in *.* wherever xyz@abb.com is available with ' '. Could below command work fine or let me know the correct command:

sed -n 's/xyz@abb.com//g' *.*

Thank you.
4 REPLIES 4
H.Merijn Brand (procura
Honored Contributor
Solution

Re: sed command to replace string

Depends what you really want. sed does not in-place edit your files, so if you want to change that pattern *inside* each file (note that *.* implies that all files are to have a dot in the name, so "README" will not be selected), sed needs a mv afterwards

# sed 's/foo/bar/' < file > tmp
# mv tmp file

In a loop that can be done like

# for i in *.* ; do
> sed 's/foo/bar/' < $i > __$i.tmp_
> mv __$i.tmp_ $i
> done

Or use perl instead, which *can* do in-file replacements

# perl -pi -e's/foo/bar/' *.*

in your case

# perl -pi -e's/\bxyz\@abb.com\b//g' *.*

Note that I made the pattern more safe by adding two \b (word bound) assertions, so zxyz@abb.com and/or xyz@abb.common will not match.

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Indira Aramandla
Honored Contributor

Re: sed command to replace string

Hi Panchalp,

Did you mean that if you had

WSS_80_err.mail:xyz@abb.com
WSS_81_err.mail:xyz@abb.com
WSS_82_err.mail:xyz@abb.com
WSS_83_err.mail:xyz@abb.com

you wanted it to be as

WSS_80_err.mail:*.*
WSS_81_err.mail:*.*
WSS_82_err.mail:*.*
WSS_83_err.mail:*.*
WSS_ERR_80.mail:*.*

i.e. replace xyz@abb.com with *.*

Then use this.
cat filename | sed 's/xyz@abb.com/*.*/g'



IA
Never give up, Keep Trying
panchpan
Regular Advisor

Re: sed command to replace string

I liked
# perl -pi -e's/\bxyz\@abb.com\b//g' *.*

But it has replaced x_yz@abb.com also :-(

Please advise...consider i have fix one i.e. xyz.abc@abb.com

Thank you.
panchpan
Regular Advisor

Re: sed command to replace string

I thank you all for their time and help.