Multiple edits to a bunch of html files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple edits to a bunch of html files
# 1  
Old 12-15-2008
Multiple edits to a bunch of html files

I'm trying to upgrade a whole bunch of pages on my site to a new design.

I thought one way of doing it would be to enclose the content in special comment tags and then use some form of script to wrap the new html around it. Like this:

<!-- content start -->
<h1>Blah blah blah</h1>
yada yada yada
<!-- content end -->

Say I put everything that goes above <!-- content start --> into text1 and everything below <!-- content end --> into text2

Is there a way to have a script go through the directory and make those changes to the html files? That is, delete everything above <!-- content start --> and replace it with text1 and delete everything below <!-- content end --> and replace it with text2?

I have the skill to think of the idea, just not to execute it. Smilie

Any suggestions would be great!

Last edited by dheian; 12-15-2008 at 01:55 AM.. Reason: clarification
# 2  
Old 12-15-2008

I'd use server-side includes:

Code:
<!--#include file="content.html" -->

The same thing can be done with PHP.
# 3  
Old 12-15-2008
I'd rather not use includes...the content's already there, I just want to replace the stuff around it for static speed.
# 4  
Old 12-15-2008
Quote:
Originally Posted by dheian
I'd rather not use includes...

Why not?
Quote:
the content's already there,

If it weren't you couldn't include it by any means.
Quote:
I just want to replace the stuff around it for static speed.

That's what includes are for.
# 5  
Old 12-15-2008
Hi,

if you just want to replace everything before <!-- content start..> and
everything after <!-- content end...> with the text from two files, this
should work:

Code:
for file in *html
do
  cat text1 && sed -n '/<!-- content start/,/<!-- content end/p' ${file} && cat text2 >> tmp
  mv tmp ${file}
done

It takes the names of all *.html files in your directory. Prepend text1,
prints the content of $file between your two markes and append text2.
The output is written to tmp which is then renamed to $file.

HTH Chris
# 6  
Old 12-15-2008
Thanks Chris.

Just tested it out, putting test text "The above stuff" in text1 and "The below stuff" in text2.

When I checked the test file, the only text it now contained was "The below stuff"

The stuff above and between (and including) the two comments was gone
# 7  
Old 12-15-2008
yupp, my error, forgot the {..}.
You have to enclose the three commands before ">>" in braces:

Code:
{cat text1 && sed -n '/<!-- content start/,/<!-- content end/p' ${file} && cat text2} >> tmp

This should work.

HTH Chris
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Merge Multiple html files into one

Hi all I have written some code to write my output in html. As i have multiple servers, need to generate single html file. but my code is generating html file for each server. I have merged the files using below code. cat /home/*_FinalData.html > /home/MergedFinalData.html But how to... (1 Reply)
Discussion started by: Snehasish
1 Replies

2. Shell Programming and Scripting

Parse multiple html files in directory

I have downloaded source code for 97 files using: wget -x -i link.txt then run a rename loop: for file in * do mv $file $file.txt done to keep the html tags but make the file a text that can be parsed. In each of the 97 txt files the gene # is variable, but the gene is associated... (15 Replies)
Discussion started by: cmccabe
15 Replies

3. Shell Programming and Scripting

How to rename bunch of files on sftp?

Hi All, I am trying to move all processed .csv files on sftp to archive dir . I tried to use wildcard *.csv but its not working . Is there any way to do this. I appreciate your help. Regards, raj (1 Reply)
Discussion started by: rajeevm
1 Replies

4. UNIX for Advanced & Expert Users

Mutt for html body and multiple html & pdf attachments

Hi all: Been racking my brain on this for the last couple of days and what has been most frustrating is that this is the last piece I need to complete a project. There are numerous posts discussing mutt in this forum and others but I have been unable to find similar issues. Running with... (1 Reply)
Discussion started by: raggmopp
1 Replies

5. UNIX for Dummies Questions & Answers

multiple text edits inone pass

File_1 looks like: bunch of text Untitled Placemark bunch of text bunch of text Untitled Placemark bunch of text bunch of text Untitled Placemark bunch of text File_2 looks like: Title_001 Title_002 Title_003 First: I need to replace the 1st occurence of "Untitled Placemark"... (2 Replies)
Discussion started by: kenneth.mcbride
2 Replies

6. Shell Programming and Scripting

Remove the first two records from a bunch of files

Hi, i have lots of single-column text files in a directory and i want to remove from each of them the first two lines and print the result in multiple new single-column files. i know that for one file the below tail command would just do the job : tail -n +3 filename > new_filename is there... (4 Replies)
Discussion started by: amarn
4 Replies

7. Shell Programming and Scripting

Replace Characters for bunch of Files.

Hi, I am new to unix and looking out for some help in reading a file contents and replacing the characters, the requirement is I having a folder and having nearly 300 txt files, all the file contents contains some words we need to iterate all each and every files and need to find and replace it... (1 Reply)
Discussion started by: subrahmaniank
1 Replies

8. Shell Programming and Scripting

Renaming a bunch of files

This is possibly a FAQ, but I was unable to find an answer: let's say you have two files named "hello.txt" and "goodbye.txt" and you want them to be "hi.txt" and "seeyou.txt". The typical regular expressions renamer apps do not apply, as you want different new names for each one of the files. The... (2 Replies)
Discussion started by: tokland
2 Replies

9. UNIX for Dummies Questions & Answers

How do I rename a bunch of files at once?

I have about 3000+ files name P08DDD that I want to rename U08DDD. How can I do this using a single command? (8 Replies)
Discussion started by: bbbngowc
8 Replies

10. Shell Programming and Scripting

Renaming a bunch of files

Hi Can any body help me reg. this problem? The problem is the format of the shell script should be >renam old new rename: it renames all files in current directory from old extension to new extension old: it is the old extension of file name (including the '.' ) new: its the new extension ... (2 Replies)
Discussion started by: Prashanth.m
2 Replies
Login or Register to Ask a Question