Operating System - HP-UX
1860559 Members
2850 Online
110412 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:[email protected]
WSS_81_err.mail:[email protected]
WSS_82_err.mail:[email protected]
WSS_83_err.mail:[email protected]
WSS_ERR_80.mail:[email protected]
WSS_ERR_81.mail:[email protected]
WSS_ERR_82.mail:[email protected]
WSS_ERR_83.mail:[email protected]

Now I wish to replace in *.* wherever [email protected] is available with ' '. Could below command work fine or let me know the correct command:

sed -n 's/[email protected]//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 [email protected] and/or [email protected] 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:[email protected]
WSS_81_err.mail:[email protected]
WSS_82_err.mail:[email protected]
WSS_83_err.mail:[email protected]

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 [email protected] with *.*

Then use this.
cat filename | sed 's/[email protected]/*.*/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 [email protected] also :-(

Please advise...consider i have fix one i.e. [email protected]

Thank you.
panchpan
Regular Advisor

Re: sed command to replace string

I thank you all for their time and help.