Think of strings, such as:
I have two apples
He has 4 apples
They have 10 pizzas
I would like to substitute every digit number I find with in a string with a different value, calculated with an external script. In my case, the python program digit_to_word.py
convert a digit number to the alphabetic format, but anything will be ok so that I can get the process.
Expected output:
I have two apples
He has four apples
They have ten pizzas
Conceptually:
echo "He has four apples" |
while read word;
do
if [[ "$word" == +([0-9+]) ]]; then
NUM='${python digit_to_word.py "$word"}'
$word="$NUM"
fi
done |
other_operation... | etc..
I say conceptually because I did not get even close to make it work. It is hard to me to even find information on the issue, simply because I do not exactly know how to conceptualize it. At this point, I am mostly reasoning on process substitution, but I am afraid it is not the best way.
Any hint that could be really useful. Thanks in advance for sharing your knowledge with me!