Skip to content

Instantly share code, notes, and snippets.

@mattkenefick
Last active August 25, 2023 04:29
Show Gist options
  • Save mattkenefick/6ff3d3b4b17c1e9f43d0908cf830bbd2 to your computer and use it in GitHub Desktop.
Save mattkenefick/6ff3d3b4b17c1e9f43d0908cf830bbd2 to your computer and use it in GitHub Desktop.

Revisions

  1. mattkenefick revised this gist Jan 9, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -44,6 +44,6 @@ Results:

    The copy and paste example will create the two example files, the merge script, make it executable, execute it, then display the results.

    Note: This will not execute properly on Windows Cmder because of the multi-line EOF. It should work just fine in a standard terminal, Git bash, etc.
    Note: This will not execute properly on Windows Cmder because of the multi-line heredoc. It should work just fine in a standard terminal, Git bash, etc.


  2. mattkenefick revised this gist Jan 9, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # Purpose

    If you're making a project where you need a base level of configs and various combinations of overrides... this `merge.sh` script will let you combine multiple `.env` or `.ini` files (key/value) and remove duplicates based on the key.

    # Usage Example

  3. mattkenefick revised this gist Jan 9, 2019. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,15 +2,17 @@
    # Usage Example

    Create both files in a structure like:
    ```
    specific.env
    base.env
    merge.sh

    ```

    Run
    sh merge.sh specific.env base.env
    `sh merge.sh specific.env base.env`

    Results:
    cat merged.env
    `cat merged.env`


    # Copy and Paste Example
  4. mattkenefick created this gist Jan 9, 2019.
    44 changes: 44 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@

    # Usage Example

    Create both files in a structure like:
    specific.env
    base.env
    merge.sh

    Run
    sh merge.sh specific.env base.env

    Results:
    cat merged.env


    # Copy and Paste Example

    echo 'name=Barbara Miller
    city=Brooklyn' > specific.env;

    echo 'name=John Doe
    city=Manhattan
    state=NY
    zip=10001' > base.env;

    cat > merge.sh <<\EOF
    #!/bin/bash
    cat $1 > tmp0
    cat $2 >> tmp0
    awk -F "=" '!a[$1]++' tmp0 > tmp1 && mv tmp1 merged.env && rm tmp0
    EOF

    chmod 0755 merge.sh;

    sh merge.sh specific.env base.env;

    cat merged.env;


    The copy and paste example will create the two example files, the merge script, make it executable, execute it, then display the results.

    Note: This will not execute properly on Windows Cmder because of the multi-line EOF. It should work just fine in a standard terminal, Git bash, etc.


    4 changes: 4 additions & 0 deletions base.env
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    name=John Doe
    city=Manhattan
    state=NY
    zip=10001
    7 changes: 7 additions & 0 deletions merge.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    #!/bin/bash

    cat $1 > tmp0
    cat $2 >> tmp0

    awk -F "=" '!a[$1]++' tmp0 > tmp1 && mv tmp1 merged.env && rm tmp0

    2 changes: 2 additions & 0 deletions specific.env
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    name=Barbara Miller
    city=Brooklyn