---
title: "Clean Up Nomad Job Plan Diffs with Bash | Ameya Shenoy"
description: "Make Nomad job plan output easier to read with a Bash script that cleans up template diffs. Explore the script and usage notes in this guide by Ameya Shenoy."
canonical: "https://www.codingcoffee.dev/blog/nomad-plan-diff"
published: "2026-03-25"
tags: "blog"
---

# Nomad Plan Diff

By Ameya Shenoy · Published 2026-03-25

Make Nomad job plan output easier to read with a Bash script that cleans up template diffs. Explore the script and usage notes in this guide by Ameya Shenoy.

Understanding `nomad` diffs is a big pain

**`~/.local/bin/nomad-tmpl-diff`** (or wherever you keep scripts):

```bash
#!/usr/bin/env bash
# Usage: nomad job plan foo.hcl 2>&1 | nomad-tmpl-diff
grep "EmbeddedTmpl:" | sed 's/.*EmbeddedTmpl:[[:space:]]*//' | while IFS= read -r val; do
  diff \
    <(echo "$val" | awk -v SIDE=L -f ~/.local/bin/nomad_diff.awk) \
    <(echo "$val" | awk -v SIDE=R -f ~/.local/bin/nomad_diff.awk)
done
```

**`~/.local/bin/nomad_diff.awk`**:

```awk
{
  p = "\\n\" => \""
  idx = index($0, p)
  left = substr($0, 2, idx - 2)
  right = substr($0, idx + 8)
  sub(/"$/, "", right)
  s = (SIDE == "L") ? left : right
  gsub(/\\n/, "\n", s)
  gsub(/\\"/, "\"", s)
  printf "%s\n", s
}
```

Then just run and see the magic!

```bash
nomad job plan monitoring.hcl | nomad-tmpl-diff
```

Note:
- The inline quoting for awk's `gsub` with escaped quotes is a nightmare in bash — the separate `.awk` file avoids that entirely and actually works reliably.

---

Canonical page: https://www.codingcoffee.dev/blog/nomad-plan-diff

[Site guide](/llms.txt) · [Contact](/contact) · [Sitemap](/sitemap-index.xml)
