The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Why does my script not work? (Noob Alert) bronkeydain Shell Programming and Scripting 4 02-21-2008 12:45 PM
noob. need help to create a script. aron Shell Programming and Scripting 1 07-09-2007 05:13 PM
sed formatting query gopsman Shell Programming and Scripting 2 05-10-2007 12:07 AM
sed formatting query gopsman Shell Programming and Scripting 2 05-09-2007 06:46 AM
Using PHP script with crontab (NOOB) Bobafart UNIX for Dummies Questions & Answers 5 04-26-2007 06:32 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-02-2008
Registered User
 

Join Date: Mar 2008
Posts: 6
Noob, script formatting query

Hi all, im new to the forums and i hope im not asking a heavily posted Q but here goes.
I use the following script to do a simple calculation, the problem is, the data i receive is in the form of numbers with commas i.e.
1,000,000
This code below wont recognise the commas so i have to remove them. If anyone has a simple solution or even point me in the right direction that would be grand. It's a little hard to search for an error with such a common word like "comma".

Code:
#! /bin/bash

        echo "What is the Lowest Threshold?" ;
        read LOW ;
        echo "What is the highest Threshold?";
        read HIGH ;
        echo "How much data have you received?";
        read DATA ;
        THRESHOLD=`expr $HIGH - $LOW` ;

                if [ "$DATA" -gt "$HIGH" ] ; then
                DIFF=`expr $DATA - $HIGH` ;
                DATA=`echo "scale=2; ( $DIFF / $THRESHOLD ) * 100" | bc` ;
                echo "$DATA percent above the threshold.";
                echo "Press 'enter' to continue" ;
                read cont ;
                elif [ "$DATA" -lt "$LOW" ] ; then
                DIFF=`expr $LOW - $DATA` ;
                DATA=`echo "scale=2; ( $DIFF / $THRESHOLD ) * 100" | bc` ;
                echo "$DATA percent below the threshold.";
                echo "Press 'enter' to continue" ;
                read cont ;
                else
                echo "This data is within the threshold limits.";
                echo "Press 'enter' to continue";
                read cont ;
                fi;
Thanks if anyone can help.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-02-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,473
excuse me if am wrong

do you want to strip commas from the input ?

Code:
echo 1,000,000 | sed 's/,//g'
Reply With Quote
  #3 (permalink)  
Old 03-03-2008
Registered User
 

Join Date: Mar 2008
Posts: 6
Yes, that's all i was after. Thank you for that.
As you can see im not the very good at scripting yet, this is probably a better job for something like perl. In any case, thanks for your help.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0