Last active
December 16, 2015 19:49
-
-
Save AntoineTurmel/5487467 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 .dtd file | |
# based on the en-US file and keeping original comments | |
#en-US base folder | |
dtd_base_folder='/home/antoine/Dev/nightingale-l10n/locales/en-US/songbird/' | |
for lang_code in $(cat /home/antoine/Dev/songbird-l10n/shipped-locales) | |
do | |
for dtd_file in $dtd_base_folder*.dtd; do | |
dtd_file=`basename $dtd_file` | |
dtd_cur_file='/home/antoine/Dev/songbird-l10n/locales/'$lang_code'/songbird/' | |
# Read all lines of dtd | |
while read line | |
do | |
mavar=`echo -e "$line"` | |
# cut the string to the " caracter | |
mavar2=`echo "$mavar" | sed 's!^\([^"]*\)".*$!\1!'` | |
checkcomm=`echo "$mavar2" | cut -c 1-4` | |
# Check if we have a comment | |
if [ "$checkcomm" == '<!--' ] | |
then | |
mavar3="$mavar2" | |
#echo "comment "$mavar3 | |
echo $mavar3 >> $dtd_cur_file$dtd_file.new | |
else | |
# remove spaces before and after string | |
mavar4=`echo "$mavar2" | sed 's/^\ *//;s/\ *$//'` | |
fi | |
# Check if we have an empty line | |
if [ "$checkcomm" == "" ] | |
then | |
#echo "empty line" | |
echo "" >> $dtd_cur_file$dtd_file.new | |
else | |
if [ "$mavar4" == "" ] | |
then | |
echo "" | |
else | |
cat $dtd_cur_file$dtd_file | grep ^"$mavar4"" " >> $dtd_cur_file$dtd_file.new | |
fi | |
fi | |
done < $dtd_base_folder$dtd_file | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment