I'm currently working on a project where we have a .properties file containing thousands of kvp's. Some of these kvp's exist multiple times... so I want to remove the duplicate lines (if they are identical of course). But I'm also afraid that some keys are duplicate, but have different values.
I'm pretty sure there are much easier ways to do it, but I want to pick up bash scripting as an additional skill, but... I basically have zero bash knowledge. Nonetheless I came up with the following solution, but I highly doubt this is the most efficient way to do this. Is there an easier way to do this?
#! /bin/bash
# Remove unique lines (key and value are equal)
sort $1 | uniq > temporary.tmp
# Find keys that are not unique
doubleKeys=`awk -F"=" '{print $1}' temporary.tmp | sort | uniq -d`
if [ -z $doubleKeys ] ; then
mv temporary.tmp final.txt
echo "Removed doubles, final file is final.txt"
else
echo $doubleKeys > DoubleKeys.log
rm temporary.tmp
echo "Double keys found with different values, see DoubleKeys.log"
fi