Skip to content

Instantly share code, notes, and snippets.

@code-hunger
Created June 14, 2017 14:05
Show Gist options
  • Save code-hunger/40d28682628186b8e7568da7a0645dcd to your computer and use it in GitHub Desktop.
Save code-hunger/40d28682628186b8e7568da7a0645dcd to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Exactly 1 argument expected - the path to the repo."
exit -1
fi
file=$1/Ultimate_Geography/Ultimate_Geography.json
# The subshell below reads from Ultimate_Geography.json so we should not write to it directly.
# That's why we save everything to a temp file first, and only then move it to the original.
temp_output=$(mktemp)
{
# Print the first 792 lines from the original file
# This is up to the "[ 'notes': " part and contains the custom settings.
head -n 792 <(git cat-file blob HEAD:$file);
# Take lines from 793 on, which contain the notes information, and remove any "marked" tags
tail -n +793 $file | awk '
/"marked"/ {
if(last ~ /,\s*$/) last=substr(last, 1, length(last)-2)
}
NR>1 && last!~"marked" { print last}
{ last = $0 }
END { print last }'
} >$temp_output
mv $temp_output $file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment