# Using sed to Create Book Indexes: Lessons from a Publishing Workflow

Original title: Using sed to make indexes for books (long)

> Hacker News story 49016917 · language: en · submitted 2026-07-23
> Web version: https://zeli.app/story/49016917
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 66 · by [TMWNN](<https://news.ycombinator.com/user?id=TMWNN>) · 💬 15
[original](<https://www.pement.org/sed/make_indexes.txt>) · [HN discussion](<https://news.ycombinator.com/item?id=49016917>)

## Summary

I needed to automate book index creation after typesetting, moving from manual entry to a sorted file. While an awk script worked, I discovered a more concise sed solution. However, a single formatting error in the input could break the entire process. I explain how the script fails and offer a robust fix to validate data before processing.

## Key quote

> If one line anywhere in the file was in error, the script would fail to change every other line after that.

## HN discussion (15 comments)

### [tomhow](<https://news.ycombinator.com/item?id=49062093>)

> Previously:
>
> Using sed to make indexes for books (1997) - https://news.ycombinator.com/item?id=16080505 - Jan 2018 (17 comments)

### [janandonly](<https://news.ycombinator.com/item?id=49060875>)

> Two thought:
>
> 1. I feel the use of AWK, SED, GREP and Bash (to name a few) is general waning. I rarely see it outside of HN posts. I wish I were better at using it. Sometimes for a special need I’ll ask a LLM to write me a script in bash just to keep this spirit alive.
>
> 2. On the other hand, I’ve written a book and added an index by using Microsoft Word, and it was basically pretty easy to add. I don’t know why I should want to go back to a world of intricate command line tools to do a job that should just be easy enough?

---

## Cite

- Page: https://zeli.app/story/49016917
- Date: 2026-07-23
- Source: pement.org (https://www.pement.org/sed/make_indexes.txt)
- Hacker News: https://news.ycombinator.com/item?id=49016917

## Other languages

- zh: https://zeli.app/zh/story/49016917 · markdown: https://zeli.app/zh/story/49016917.md
- ja: https://zeli.app/ja/story/49016917 · markdown: https://zeli.app/ja/story/49016917.md
- ko: https://zeli.app/ko/story/49016917 · markdown: https://zeli.app/ko/story/49016917.md
- de: https://zeli.app/de/story/49016917 · markdown: https://zeli.app/de/story/49016917.md
- es: https://zeli.app/es/story/49016917 · markdown: https://zeli.app/es/story/49016917.md
