Skip to content

Instantly share code, notes, and snippets.

@oliverralbertini
Last active October 4, 2019 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliverralbertini/add73c17e02e39c59623d1df145992c9 to your computer and use it in GitHub Desktop.
Save oliverralbertini/add73c17e02e39c59623d1df145992c9 to your computer and use it in GitHub Desktop.
merge krb5.conf files
BEGIN {
block_length = 0
block_has_diff = 0
}
{
if ( $0 ~ /{.*{/ || block_length ) {
if ( $1 != $2 )
block_has_diff++
block1[block_length] = $1
block2[block_length] = $2
block_length++
} else if ($1 == $2 || $1 ~ /default_realm/) {
print $1
} else {
print $1
print $2
}
if ( $0 ~ /}.*}/ ) {
for (i=0; i<block_length-1; i++)
print block1[i]
print $1
if (block_has_diff) {
for (i=0; i<block_length-1; i++)
print block2[i]
print $2
block_has_diff = 0
}
block_length = 0
}
}
@oliverralbertini
Copy link
Author

This script can be called like this:

paste -d'|' dataproc_{,2_}env_files/krb5.conf | awk -F'|' -f test.awk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment