Created
April 16, 2014 16:55
-
-
Save l04m33/10906622 to your computer and use it in GitHub Desktop.
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 | |
function get_new_names() { | |
local input_names=$1 | |
sed 's/[ \t]\+/:/g' $input_names | |
} | |
function gen_subst_func() { | |
local from=$1 | |
local to=$2 | |
local func_name=$3 | |
eval " | |
function $func_name () { | |
sed \"s/$from/$to/g\" | |
}" | |
} | |
main() { | |
local input_names=$1 | |
if [ -z "$input_names" ]; then | |
echo "Usage: $0 <config file>" 1>&2 | |
exit 1 | |
elif [ ! -e "$input_names" ]; then | |
echo "File \"$input_names\" not found" 1>&2 | |
exit 1 | |
fi | |
local new_names=$(get_new_names $input_names) | |
local i=1 | |
local chain_str='' | |
local func_name='' | |
for nn in $new_names; do | |
gen_subst_func "${nn%%:*}" "${nn##*:}" "subst_func_$i" | |
chain_str="$chain_str | subst_func_$i" | |
i=$(expr $i + 1) | |
done | |
eval "cat $chain_str" | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment