|
|
#1 |
|
Triple-A Player
Join Date: May 2004
Posts: 158
|
sed maybe? replacing a word in many docs
Hi
I got this website that I'm hosting in our own servers. It runs on apache. The designer who created it made all the links and the html files with the extention .htm and not .html. In order for this to work, I had to change the apache configuration to look for index.htm instead of the default index.html. Since we're gonna have another site (virtual host on the same computer) made by another designer who uses the extentions .html, I would like to replace every occurrence in all html files, inside the first site's folder, from .htm to .html. What would be the best approach so I don't have to manually edit every single html file so all the links have .html at the end? |
|
|
|
|
|
#2 |
|
Prospect
Join Date: Feb 2005
Location: San Diego
Posts: 7
|
I Think
I believe you can change your httpd.conf file to read both of them, by adding the index.htm instead of changing it.
|
|
|
|
|
|
#3 |
|
Triple-A Player
Join Date: May 2004
Posts: 158
|
Like this?
# The index.html.var file (a type-map) is used to deliver content- # negotiated documents. The MultiViews Option can be used for the # same purpose, but it is much slower. # DirectoryIndex index.html index.html.var index.htm index.htm.var |
|
|
|
|
|
#4 |
|
Prospect
Join Date: Feb 2005
Location: San Diego
Posts: 7
|
Hmm
Mine looks like this:
# DirectoryIndex: Name of the file or files to use as a pre-written HTML # directory index. Separate multiple entries with spaces. # <IfModule mod_dir.c> DirectoryIndex index.html index.htm </IfModule> |
|
|
|
|
|
#5 |
|
MVP
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
|
From what I read you want to not only change the index but also all htm/html files.
I found this save this as an executable file Code:
#!/bin/tcsh
set fn_new={$1:r}.$2
echo renam $1 $fn_new
mv $1 $fn_new
Code:
find ~/Desktop/webfolder -name "*.htm" -exec ./renamex {} html \;
This will change all htm file to html in the directory and sub directories I am assuming that you do not have spaces in file name and directories. As from what I understand this will not like them. This script is from http://www.osxfaq.com/tips/unix-tric...9/wednesday.ws |
|
|
|
|
|
#6 |
|
Major Leaguer
Join Date: Oct 2003
Location: Santa Fe
Posts: 372
|
A 2 part solution...
This will be a 2 part solution.
this Applescript will make a text file on your desktop of all files with the extension you tell it to find in the folder you tell it to look in: Code:
property fileExt : ".html" tell application "Finder" set inFolder to choose folder with prompt "Select a folder:" default location (home as string) & "Sites" as alias display dialog "What kind of file:" default answer fileExt set fileExt to the text returned of the result end tell do shell script "find " & POSIX path of inFolder & " -type f -name '*" & fileExt & "' > ~/Desktop/FilesProcessed.txt" Last edited by Gnarlodious; 02-15-2005 at 01:55 AM. |
|
|
|
|
|
#7 |
|
Major Leaguer
Join Date: Oct 2003
Location: Santa Fe
Posts: 372
|
this will take your list of files and do the sed replacement on every file listed. but watch out, it will also change links to other domains so it will need some postrun checking.
These 2 scripts can easily be combined into one but for the beginner it makes it easier to understand what's going on with separate scripts. Code:
tell application "Finder" to set someFile to file "FilesProcessed.txt" of desktop as alias open for access someFile read someFile set fileList to paragraphs of the result close access someFile repeat with someFile from 1 to count of fileList set thisFile to item someFile of fileList if thisFile is not "" then do shell script "tr -s '\\r' '\\n' < " & thisFile & " > /private/tmp/tempFile" do shell script "sed 's|\\.htm\"|\\.html\"|g' /private/tmp/tempFile > " & thisFile end if end repeat http://Gnarlodious.com/Apple/AppleScript/ |
|
|
|
|
|
#8 |
|
Triple-A Player
Join Date: Feb 2005
Location: Bellevue, WA
Posts: 233
|
or you can run this in the affected directories....
Code:
#/bin/bash #appends the letter l to the end of all filenames ending in .htm for filename in *htm do mv "filename" "$filename"l done #replaces all .htm with .html inside the files for filename in *html do cat "$filename" | sed 's/.html/.htm/g' | sed 's/.htm/.html/g' > "$filename".tmp mv "$filename".tmp "$filename" done sed turns all html's to htm's to begin with, so you don't end up with htmll's at the end. You may have to "tweak" the sed replacements to ensure that you only change hrefs that point to your pages. (instead of ones pointing to outside pages.) Unfortunately, that is not always as easy as it sounds..... Chris. Last edited by weltonch777; 02-20-2005 at 09:12 AM. |
|
|
|
|
|
#9 |
|
Triple-A Player
Join Date: May 2004
Posts: 158
|
thanks a lot for all the help guys
|
|
|
|
|
|
#10 | |||||||||||||||||||
|
All Star
Join Date: Jul 2004
Posts: 713
|
You could also use perl for that part: Code:
perl -i -p -e 's/.html/.htm/g; s/.htm/.html/g;' $filename |
|||||||||||||||||||
|
|
|
|
|
#11 | |||||||||||||||||||||||
|
Triple-A Player
Join Date: Feb 2005
Location: Bellevue, WA
Posts: 233
|
Very nice.. I shall remember that Chris |
|||||||||||||||||||||||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|