You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
#!/bin/sh
|
|
|
|
sum=0
|
|
while read line; do
|
|
num1="$(echo "$line" | sed -n 's/^[^0-9]*\([0-9]\).*/\1/p')"
|
|
num2="$(echo "$line" | sed -n 's/.*\([0-9]\)[^0-9]*$/\1/p')"
|
|
sum=$(( $sum + $num1$num2 ))
|
|
done < "$1"
|
|
echo "$sum"
|
|
|
|
sum=0
|
|
while read line; do
|
|
line1="$(echo "$line" | sed \
|
|
-e 's/\(one\|two\|three\|four\|five\|six\|seven\|eight\|nine\)/%\1%/' \
|
|
-e 's/%one%/1/' \
|
|
-e 's/%two%/2/' \
|
|
-e 's/%three%/3/' \
|
|
-e 's/%four%/4/' \
|
|
-e 's/%five%/5/' \
|
|
-e 's/%six%/6/' \
|
|
-e 's/%seven%/7/' \
|
|
-e 's/%eight%/8/' \
|
|
-e 's/%nine%/9/')"
|
|
line2="$(echo "$line" | sed \
|
|
-e 's/.*\(one\|two\|three\|four\|five\|six\|seven\|eight\|nine\)/%\1%/' \
|
|
-e 's/%one%/1/' \
|
|
-e 's/%two%/2/' \
|
|
-e 's/%three%/3/' \
|
|
-e 's/%four%/4/' \
|
|
-e 's/%five%/5/' \
|
|
-e 's/%six%/6/' \
|
|
-e 's/%seven%/7/' \
|
|
-e 's/%eight%/8/' \
|
|
-e 's/%nine%/9/')"
|
|
num1="$(echo "$line1" | sed -n 's/^[^0-9]*\([0-9]\).*/\1/p')"
|
|
num2="$(echo "$line2" | sed -n 's/.*\([0-9]\)[^0-9]*$/\1/p')"
|
|
sum=$(( $sum + $num1$num2 ))
|
|
done < "$1"
|
|
echo "$sum"
|
|
|