I have a JSON master config file whose value may be overwritten by a specific account's config file (also in JSON). The Master file has this structure:{    section1Configs: {        setting01: true,        setting02: true,        setting03: false    },    section2Configs: {        setting01: true,        setting02: true,        setting03: false    },    section3Configs: {        setting01: true,        setting02: true,        setting03: false    },    section4Configs: {        setting01: true,        setting02: true,        setting03: false    }}The config file for a specific account may look like this:{    section1Configs: {        setting01: true,        setting02: true,        setting03: true    },    section2Configs: {        setting01: false,        setting02: true,        setting03: false    },    section3Configs: {        setting01: true,        setting02: false,        setting03: false    },    section4Configs: {        setting01: true,        setting02: true,        setting03: false    }}Note that they are identical except certain values (section01Config.setting03, section02Config.setting01, and section03Config.setting02) are different. Note also that the entire section4Configs block is the same in both files.The ones that are the same are not needed since the application loads both and overwrites the Master file with the ones that are different in the account config.What I would like to do is have a script that iterates through a directory of such account files and deletes the entry in each file that are the same key and value as the Master file. From this example I would end up with a file like this:{    section1Configs: {        setting03: true    },    section2Configs: {        setting01: false    },    section3Configs: {        setting02: false    }}There are over 200 account config files and doing this manually will take a lifetime. Any help is greatly appreciated!------ EDIT -------I tried to keep the question simple but I think a missing detail will have an impact on the answer.The account and config JSON file consist of sections and their corresponding settings. This means that the JSON is one level deeper than what's mentioned above:{    section1Configs: {        level1Settings: {            section01Lev01_01: true,            section01Lev01_012: true,            section01Lev01_02: true        }    }}Thanks!
Delete Entries in File if the Same Entry Exists in a Master File
shell script;scripting;json
So I copied your bottom thing into two files. File 1:{    section1Configs: {        level1Settings: {            section01Lev01_01: true,            section01Lev01_012: true,            section01Lev01_02: true        }    }}And File 2...{    section1Configs: {        level1Settings: {            section01Lev01_01: true,            section01Lev01_012: false,            section01Lev01_02: true        }    }}They only differ on the Level01_012 line.Then I did:grep -Ev '[{}]|^$' file1 | grep -Fxvf- file2{    section1Configs: {        level1Settings: {            section01Lev01_012: false,        }    }}That command is broken down as follows:grep -Ev '[{}]|^$' file1Here we ask grep to please print every line in file1 which does not match either a { character or a } character, but it must match at least one character.Its output looks like:        section01Lev01_01: true,        section01Lev01_012: true,        section01Lev01_02: truegrep -Fxvf- file2That is read by this second grep which interprets its - stdin input pattern -file as a -Fixed-string pattern -x entire-line match which it should -v not print to output. And so this second grep prints every line in file2 which doesn't exactly match the true/false lines in file1.Now if your grep does not understand - as stdin we have a few options:grep -Ev '[{}]|^$' file1 | grep -Fxvf /dev/fd/0 file2...will work on most systems. A similar option is to use /dev/stdin, which is also pretty likely to work, if a little less so. There is also a shell-specific implementation know as process-substitution which works in just about exactly the same way...grep -Fxvf <(grep -Ev '[{}]|^$' file1) file2...which may or may not work for you depending on your shell.Another possibility is...grep -Fxv $(grep -Ev '[{}]|^$' file1) file2...which may or may not work for you depending on how large the output of the command-subbed grep is.Try a few and probably you'll find one that works for you.