Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So... the split command allows me to split a file into pieces. The problem with that, though, is that only one of the files is going to contain the HTML headers, and only one of them is going to contain the HTML footers.

(this is probably relevant for a lot of other files that contain header/footer information)

share|improve this question
You're going to need a utility that's specialized to HTML. There are plenty of utilities that generate split HTML files from sources in other markup languages, but it's rare to process HTML files (because the structure is often hard to analyse). Where did you get the HTML files you want split, and what do you want to do with them? There may well be an easier way to do what you want than splitting the HTML. – Gilles Sep 6 '11 at 7:29
up vote 1 down vote accepted

Most unix tools, like split, are file format agnostic. To split files that use a specific format (like HTML) into smaller validly formatted files, use specific tools. For HTML splitting, htmldoc is the first I found looking quickly on the web. It has been packaged (at least in debian, ubuntu, fedora, gentoo, etc…).

Do not use sed-ish tricks that make troublesome assumptions on the files, as it would backfire one day or the other.

share|improve this answer

You could first extract and remove the header/footer of the source file, split it and add the extracted header/footer to each split.

You could use xpath or sed to do the editing of the source file.

For example this command line strips the header footer of a file:

$ sed -e '0,/<body>/d' -e '/<\/body>/,$d input.html

Where sed is the GNU one and it is assumed that a body tag is on its own line.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.