Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SED substitution question 2

Status
Not open for further replies.

AnotherAlan

Technical User
Feb 10, 2006
362
0
0
GB
Hi all,

I need to do some substitutions in php pages after changing my web server.
I have written this, which works;
sed 's:\/opt\/SunOne-6.1\/docs:\/usr\/local\/apache2\/htdocs:g' > appdocs.php.test

However, I also have a directory path that starts /app.

My question is - Is it possible to write one sed statement that can substitute for either occurence of app or opt?

Something like sed 's:\/[opt | app]... blah blah. or would I need to use two sed statements?

Thanks
Alan
 
Apologies,

Seems as though I didn't search the forum properly.

Oops!
Alan
 
What's up Alan,

You're on the right track.

sed 's/V[app|opt]...' should work.

borne2bash
 
Hey borne2bash,

Thanks for the reply, you'd think that it should work, but not for me I'm afraid.
I've tried in ksh and bash, but no luck, syntax below

sed 's:\/\[opt|app]\/:\/usr:g'
and
sed 's:\/[opt|app]\/:\/usr:g'

Is it my escaping? Or am I just trying too hard to do something that could quite easily be done with a couple of sed statements?

Cheers for your input though, much appreciated.

Time to go home I think.
Alan
 
Perhaps this ?
sed 's:/[oa]p[tp]/SunOne-6.1/docs:/usr/local/apache2/htdocs:g'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
GENIUS, every time PHV, every time.

Thank you very much.
I was getting a little too happy with those escapes!!

Of course now I have to stay at work and play around with sed...

As always, much appreciated.

Alan
 
Just another idea to mull over (I know you have a solution already), but I recently discovered the -r option for GNU sed which allows you to use extended regular expressions, e.g.

[tt]sed 's:/(opt|app)/SunOne-6.1/docs:/usr/local/apache2/htdocs:g' [/tt]

...which is I think what borne2bash was heading for.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top