It isn't clear to me what you want to do. Do you want the contents in file 1, between the <HEAD> and </HEAD> tags to be deleted and replaced
with the contents of file2.
You could do the deletion in sed pretty easily:
Code:
$ sed '/<head>/,/<\/head>/{
/<head>/n;
/<\/head>/n;
d }' file1.htm
I saved this page and ran the above command in cygwin.
Here are the first 5 lines of the result:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" lang="en">
<head>
</head>
<!-- logo -->
If the <head> and </head> tags might not be alone on the same line, you will need to adjust the sed command.
For example, for the line containing the <head> tag:
/<head>/s/^\(.*\)<head>.*/\1<head>/n;
This will preserve what came before <head>, deleting what came after. It will fail if the pattern is:
something .... <head> more junk ... </head> more junk.
Because what you seam to be doing is creating an html document out of a template, I would recommend that instead you break the file1 template into two pieces and instead either cat the three files together, or use a here document.
Code:
cat >file.htm <<- "HEAD"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" lang="en">
<head>
HEAD
cat >>file.htm <file2
cat >>file.htm <<- "TAIL"
</head>
</html>
TAIL
or
Code:
cat head >file.htm
cat file2 >>file.htm
cat tail >>file.htm