Sed with wild-cards

Discuss Applications
Post Reply
TheQuirk
programmer
programmer
Posts: 114
Joined: Wed Jan 22, 2003 4:11 pm

Sed with wild-cards

Post by TheQuirk »

All righty, here's my problem: I need to replace a (batch) of links to point to one page. Would "sed" accept a wild card? Would this work (I don't have access to my website right now so I can't check):

for i in /home/glezhe/www/* ; do sed 's%http://www.belg88.com/friends/*%notnow.php%g' $i > $i.new ; done

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

If you want to replace text in all HTML files in a directory this is a good way to do it:

Code: Select all

perl -i -p -e "s/OLD/NEW/g;" *.html
where "OLD" is the text you want to replace and "NEW" is the text you want to replace it with. Or if you want to change it on your entire web site:

Code: Select all

cd /var/www/html
find -name '*.html' | xargs perl -i -p -e "s/OLD/NEW/g;"
Should work.

This will change text in the file, and not save a backup of the file so you might want to have backups in case you change more than you want.

TheQuirk
programmer
programmer
Posts: 114
Joined: Wed Jan 22, 2003 4:11 pm

Post by TheQuirk »

All righty, I'll do it in a moment and see if it works (the string I want to replace contains a slash, so I will either endup using a "&" sign instead of the slash and I want sed to read, though).

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main »

It should be able to handle slashes if you put a backslash in front of it "\/" in your OLD/NEW.

X11
guru
guru
Posts: 676
Joined: Sun Jan 19, 2003 11:09 pm
Location: Australia
Contact:

Post by X11 »

hmmmmmmmmmm

Post Reply