Skip to content

Instantly share code, notes, and snippets.

@hbenali
Last active June 28, 2024 12:56
Show Gist options
  • Select an option

  • Save hbenali/60917b5366008dd80f83841fc8ebd7ed to your computer and use it in GitHub Desktop.

Select an option

Save hbenali/60917b5366008dd80f83841fc8ebd7ed to your computer and use it in GitHub Desktop.
Convert Java XML to Properties files and support long lines using yq https://github.com/mikefarah/yq
currentDir=$PWD
find -type d -name 'locale' | while read folder; do
cd $currentDir
echo $folder
cd $folder
find -name '*.xml' | while read file; do
tmpfile=$(echo $file | sed -E 's/.xml$/.tmp/g')
propfile=$(echo $file | sed -E 's/.xml$/.properties/g')
yq --xml-skip-directives --xml-skip-proc-inst -p=xml -o=properties --properties-separator="=" --xml-strict-mode $file | sed 's/[^.]*.//' >$tmpfile
while IFS= read -r line; do
if echo $line | grep -qP '.[0-9]+='; then
[ -z "$lineform" ] && lineform=$(echo $line | sed -E 's/.[0-9]+=/=/g') || lineform="${lineform} $(echo $line | sed 's/[^=]*=//')"
elif [ -n "$lineform" ]; then
echo $lineform >>$propfile
echo $line >>$propfile
lineform=
else
echo $line >>$propfile
fi
done <"$tmpfile"
rm $tmpfile
rm $file
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment