Link to home
Start Free TrialLog in
Avatar of light-blue
light-blue

asked on

basic sed - search and replace

How do I write a sed command, run through crontab (I'm doing crontab -e as root) and search for

http://www.company.com/somewhere

and replace with

<!-- BEGIN IDS -->{ID}<!-- END IDS -->http://www.company.com/somewhere

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of nixfreak
nixfreak

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ozo
sed -i.bak -e 's#http://www.company.com/somewhere#<!-- BEGIN IDS -->{ID}<!-- END IDS -->&#' file
Avatar of nixfreak
nixfreak

Typo.

sed 's#\(http://www\.company\.com/somewhere\)#<!- BEGIN IDS -->{ID}<!- END IDS -->\1#'
Typo.

sed 's#\(http://www\.company\.com/somewhere\)#<!-- BEGIN IDS -->{ID}<!-- END IDS -->\1#'
Avatar of light-blue

ASKER

Hmmm...it seems that none of those worked. I even tried changing the original file to have just aaabbb and running

sed 's#\(aaabbb\)#<!- BEGIN IDS -->{ID}<!- END IDS -->\1#' filename.htm

but no replacing happened.

Maybe it would more helpful (?) to say I want to replace the entire a html element tag so

http://www.somewhere.com/somplace/script.php 

becomes

<!-- BEGIN IDS -->{ID}<!-- END IDS -->http://www.company.com/someplace/somescript.php
or, more likely, I'm doing something (basic) wrong. maybe if I tried a simpler example of sed, I could figure out what I'm doing incorrectly...

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you both! They worked perfectly, but I wasn't redirecting STDOUT properly. Duh!

Thanks again!