Skip to content

Instantly share code, notes, and snippets.

@chuckwagoncomputing
Last active November 28, 2015 01:20
Show Gist options
  • Save chuckwagoncomputing/8fd3db22ab44a75853c1 to your computer and use it in GitHub Desktop.
Save chuckwagoncomputing/8fd3db22ab44a75853c1 to your computer and use it in GitHub Desktop.
WebAdd - Add up dollar values from a website

WebAdd

Script to add up dollar values from a website

webadd Test Example

webadd gets the dollar value from every line and adds them. If there is more than one dollar value on a line. you can select which one you want. Spaces or other characters between the dollar sign and numbers are not allowed.

something $5.00

two of something $3.00 x2= $6.00

You can use dollar amounts in operationals, but they will be counted as one of the values to be selected.

three of something $7.00 x2= $14.00 -$1.00= $27.00

#!/bin/bash
#This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
FILE="~/result.webadd"
TOTAL=0
if [ $# -gt 0 ]; then
URL="$1"
else
echo "Enter URL"
read URL
fi
echo "Please Wait..."
w3m $URL | while read LINE; do
FOUND=`echo $LINE | while IFS= read -r -n1 char; do echo $char | grep '\\$'; done`
if [ -n "$FOUND" ]; then
AMANY=`echo $FOUND | tr -d [:blank:] | wc -c`
MANY=$(( AMANY - 1 ))
if [ $MANY -gt 1 ]; then
echo "There are $MANY Dollar values on this line."
echo "Enter 1-first one, 2-second one, etc."
read -n 1 WHICH </dev/tty
echo
BWHICH=$(( WHICH + 1 ))
if [ $WHICH -gt $MANY ]; then
echo "There are only $MANY Dollar values on this line."
BWHICH=$AMANY
fi
else
BWHICH=2
fi
NUMBER=`echo $LINE | tr -d [:blank:] | tr -s "$" "\t" | sed 's/[x / - +][$][0-999999999][. ,][0-999999999][0-999999999]=//g' | cut -f$BWHICH`
echo "Plus"
echo $NUMBER
TOTAL=`echo $TOTAL+$NUMBER | bc -l`
echo "Equals"
echo $TOTAL
fi
done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment