Last active
December 10, 2015 12:19
-
-
Save AntoineTurmel/4433708 to your computer and use it in GitHub Desktop.
Script to reorder strings based on a file pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script allow reorder of strings from a foreign .properties file | |
# based on the en-US file and keeping original comments | |
#en-US basefile | |
prop_base_file='/home/antoine/Dev/nightingale-l10n/locales/en-US/songbird/songbird.properties' | |
for lang_code in $(cat /home/antoine/Dev/songbird-l10n/shipped-locales) | |
do | |
prop_cur_file='/home/antoine/Dev/songbird-l10n/locales/'$lang_code'/songbird/songbird.properties' | |
prop_new_file='/home/antoine/Dev/songbird-l10n/locales/'$lang_code'/songbird/songbird.properties.new' | |
# Read all lines of base file | |
while read line | |
do | |
mavar=`echo -e "$line"` | |
mavar2=`echo "$mavar" | sed 's!^\([^=]*\)=.*$!\1!'` | |
checkcomm=`echo "$mavar2" | cut -c 1-1` | |
# Check if we have a comment | |
if [ "$checkcomm" == "#" ] | |
then | |
mavar3="$mavar2" | |
echo "comment "$mavar3 | |
echo $mavar3 >> $prop_new_file | |
else | |
mavar3="$mavar2""=" | |
fi | |
# Check if we have an empty line | |
if [ "$checkcomm" == "" ] | |
then | |
echo "" >> $prop_new_file | |
fi | |
cat $prop_cur_file | grep ^"$mavar3" >> $prop_new_file | |
done < $prop_base_file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment