#!/bin/sh # # ini2moo - convert ini files into moo format # PATH=/bin:/usr/bin export PATH if [ $# -ne 2 ]; then printf "Usage: moo2ini file.ini file.moo\n" >&2 exit 2 fi ini_file="$1" moo_file="$2" if [ ! -r "${ini_file}" ]; then printf "Error: could not open '%s'\n" "${ini_file}" >&2 exit 1 fi if [ ! -r "${moo_file}" ]; then printf "Error: could not open '%s'\n" "${moo_file}" >&2 exit 1 fi awk -v application="${moo_file%.moo}" ' BEGIN { FS="=" moo_file = application ".moo" moo_keys_len = inside_app = 0 while ((getline < moo_file) > 0) if (NF==2) moo_keys[++moo_keys_len] = $1 } /^\[[^]]+\]$/ { if ($0 == "[" application "]") { inside_app = 1 } else { inside_app = 0 } next } inside_app == 1 && NF > 1 && $1 ~ /^[0-9]+$/ { value = $1 $1 = "" sub(/^[ ]+/, "") printf("%s=%s\n", moo_keys[value], $0) } ' <"${ini_file}"