PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Numerology With Bash Code Example

Go down

Numerology With Bash Code Example Empty Numerology With Bash Code Example

Post by jamied_uk 23rd July 2016, 13:35




Code:
#!/bin/bash
# Usage ./num.sh "test"
# (c) J~Net 2016
# jnet.forumotion.com/t1330-numerology-with-bash-code-example#1860
ptr=1
if [ -z "$1" ] ; then
  echo -n "Word or phrase: "
  read basis
else
  basis="$@"
fi
echo "$basis" > out.txt
basis="$( echo $basis | \
  tr '[A-Z]' '[a-z]' | \
  tr -Cd '[:alnum:]' )"
basislength="$( echo $basis | wc -c )"
echo "(Working with $basis which has \
  $basislength characters)"
while [ $ptr -lt $basislength ] ; do
  letter="$( echo $basis | cut -c $ptr )"
  ordvalue="$(echo $letter | \
    perl -e '$a=getc(); print ord($a)-96' )"
  echo "letter $letter has value $ordvalue" >> out.txt
  ptr="$(( $ptr + 1 ))"
done
# ā€ˇfilter out non numbers
cat out.txt | sed 's/[^0-9]*//g' > nout.txt
# Sum all numbers together
SUM=0; for i in `cat nout.txt`;
do SUM=$(($SUM + $i));
done;
echo "Your Words "
cat out.txt
echo "Adds up to a total of "
echo $SUM
rm nout.txt; rm out.txt
exit 0


Last edited by jamied_uk on 23rd July 2016, 16:18; edited 1 time in total
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Numerology With Bash Code Example Empty Re: Numerology With Bash Code Example

Post by jamied_uk 23rd July 2016, 16:11

Update File Link
app.box.com/s/v6xjqpnuvw2slupextct2lgzdz7azk6v
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum