Created
January 28, 2017 16:24
-
-
Save b4n/a15e6fc6cdaeb89c9657225afd481b04 to your computer and use it in GitHub Desktop.
Script to diff configuration files (INI-style)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Diffs 2 configuration files, sorting their content by sections to and key | |
# names to get a meaningful diff. | |
sed_escape() { | |
sed 's/[][/\\.$^]/\\\0/g' <<<"$1" | |
} | |
read_section_sorted() { | |
local file="$1" | |
local section="$2" | |
echo | |
echo "$section" | |
sed "$file" -n -e " | |
/^$(sed_escape "$section")/{ | |
:loop | |
n | |
/^\[/q | |
/^ *$/!p | |
b loop | |
} | |
" | sort -s | |
} | |
read_conffile_sorted() { | |
grep -e '^\[' "$1" | sort -u | while read section; do | |
read_section_sorted "$1" "$section" | |
done | |
} | |
diff -u <(read_conffile_sorted "$1") <(read_conffile_sorted "$2") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment