Sed with wild-cards

Discuss Applications

Sed with wild-cards

Postby TheQuirk » Fri Jan 24, 2003 5:28 pm

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
TheQuirk
programmer
programmer
 
Posts: 113
Joined: Wed Jan 22, 2003 4:11 pm

Postby Void Main » Fri Jan 24, 2003 5:41 pm

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.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby TheQuirk » Fri Jan 24, 2003 7:05 pm

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).
TheQuirk
programmer
programmer
 
Posts: 113
Joined: Wed Jan 22, 2003 4:11 pm

Postby Void Main » Fri Jan 24, 2003 7:13 pm

It should be able to handle slashes if you put a backslash in front of it "\/" in your OLD/NEW.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby X11 » Sat Jan 25, 2003 1:38 pm

hmmmmmmmmmm
X11
guru
guru
 
Posts: 674
Joined: Sun Jan 19, 2003 11:09 pm
Location: Australia


Return to Applications

Who is online

Users browsing this forum: No registered users and 1 guest