1833753 Members
2276 Online
110063 Solutions
New Discussion

Re: Shell

 
SOLVED
Go to solution
Victor_5
Trusted Contributor

Shell

Hi guys,

I met a problem

"Noman is good, Norman is fun"


Use "Phil" to replace "Noman" and "Norman"
How to finish it using sed?

Thanks
10 REPLIES 10
Pete Randall
Outstanding Contributor

Re: Shell

I think

sed 's|/Phil/No*man/||g'

would do it.


Pete


Pete
James R. Ferguson
Acclaimed Contributor
Solution

Re: Shell

Hi Victor:

# sed -e 's/Norman/Phil/g' -e 's/Noman/Phil/g'

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: Shell

I guess I'll take that back. Can't make it work. Damn.


Pete


Pete
twang
Honored Contributor

Re: Shell

# cat f1
Noman is good, Norman is bad!

#sed -e 's/Norman/Phil/g' -e 's/Noman/Phil/g' f1 > f2

# cat f2
Phil is good, Phil is bad!

Vasikaran Venkatesan
Frequent Advisor

Re: Shell

JFR's is good - or simply, using wild cards - u can resolve by doing this way.
sed -e 's/No[a-z]*/Phil/g'
Vasikaran Venkatesan
Frequent Advisor

Re: Shell

Sorry - it was JRF instead.
Michael Kelly_5
Valued Contributor

Re: Shell

Victor,
try:
echo "Noman is good. Norman is fun" | sed -e 's/Nor*man/Phil/g'

The r* tells sed to match 0 or more r's

HTH,
MIchael.
The nice thing about computers is that they do exactly what you tell them. The problem with computers is that they do EXACTLY what you tell them.
Pete Randall
Outstanding Contributor

Re: Shell

Thanks, Michael, that's what I was trying to come up with!


Pete


Pete
Bernhard Mueller
Honored Contributor

Re: Shell

I think Vashikaran deserves 10, this is only the final touch:

sed -e 's/No[a-z]*an/Phil/g'

Pete Randall
Outstanding Contributor

Re: Shell

Bernhard,

I think everyone but me deserves a 10!


Pete


Pete