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 and shell scripting languages 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 04:45 PM
noob. need help to create a script. aron Shell Programming and Scripting 1 07-09-2007 09:13 PM
sed formatting query gopsman Shell Programming and Scripting 2 05-10-2007 04:07 AM
sed formatting query gopsman Shell Programming and Scripting 2 05-09-2007 10:46 AM
Using PHP script with crontab (NOOB) Bobafart UNIX for Dummies Questions & Answers 5 04-26-2007 10:32 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-02-2008
benjo benjo is offline
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.
  #2 (permalink)  
Old 03-03-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,957
excuse me if am wrong

do you want to strip commas from the input ?

Code:
echo 1,000,000 | sed 's/,//g'
  #3 (permalink)  
Old 03-03-2008
benjo benjo is offline
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0