I was trying to setup an auto-update (for multiple servers) bash script via cron to a config file (text based) by downloading the new file everyday and replacing it directly. The script works fine, however there's a case where sometimes each server would need to have specific settings being different from the main config file, for example, one of the standard config line would be:


meanwhile some servers would need:


I can manually change that config line on the corresponding server, however it would get overwritten again everytime the auto-update script being run.

So the question, can I make a single bash script to download the reference config file, and then compare it first with the local config file (on the corresponding server) for any differences and then merge it?

By "merge" I mean combining the line properly into:


rather than two separate lines:


Do you really mean to merge the lists of values? That is


should be combined into


If so, you could try

BEGIN { FS = "=" }
NR == FNR && /ports_defined/ { ports=$2 }
NR > FNR {
    if ($1 == "ports_defined") {
        ports = ports "," $2
        split(ports, p, ",")
        for (i in p) {
            if (!num[p[i]]) {
                result = result "," p[i]
                num[p[i]] = 1
        print $1 "=" substr(result, 2)
    } else {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.