--- id: fae8f322-d5c6-4ffb-9735-49e9f46940e8 type: solution title: "Pi-hole v6 TOML update approach using pure shell/sed/awk" tags: [pihole, v6, toml, shell, sed, awk, solution] importance: 0.6 confidence: 0.8 created: "2026-02-07T15:12:33.508157+00:00" updated: "2026-02-07T15:12:33.508157+00:00" relations: - target: dc3ed16c-18db-4011-b866-3730316cd68d type: SOLVES direction: outgoing strength: 0.5 --- ## Approach for updating Pi-hole v6 pihole.toml without python/perl **Constraint:** Pi-hole container only has sh, sed, awk, grep **Method 1: Extract-Replace-Merge** 1. Extract everything before 'hosts = [' line 2. Write new hosts array 3. Extract everything after matching ']' 4. Concatenate all parts **Shell commands:** # Before hosts array sed -n '1,/^[[:space:]]*hosts[[:space:]]*=/p' pihole.toml | head -n -1 > part1.toml # New hosts array cat >> part1.toml <> part1.toml # Replace original mv part1.toml pihole.toml **Method 2: Line-by-line state machine with awk** awk ' BEGIN { in_hosts=0; done=0 } /^[[:space:]]*hosts[[:space:]]*=/ && !done { print " hosts = [" print " \"10.10.0.16 domain1.com\"," print " \"10.10.0.16 domain2.com\"" print " ]" in_hosts=1 done=1 next } in_hosts && /\]/ { in_hosts=0; next } !in_hosts { print } ' pihole.toml **Implementation in script:** - Build TOML_HOSTS variable with proper escaping - Inject into awk/sed command - Execute via docker exec pihole sh -c **Test first on primary, then secondary**