Noob, script formatting query

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Noob, script formatting query
# 1  
Old 03-02-2008
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.
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".

#! /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 ;
                echo "This data is within the threshold limits.";
                echo "Press 'enter' to continue";
                read cont ;

Thanks if anyone can help.
# 2  
Old 03-03-2008
excuse me if am wrong

do you want to strip commas from the input ?

echo 1,000,000 | sed 's/,//g'

# 3  
Old 03-03-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SQL Query in Shell Script output formatting

Hi All, #!/bin/ksh call_sql () { sql=$1 sqlplus -s $sqlparam_sieb <<EOF SET ECHO OFF; SET NEWPAGE NONE; SET SQLBL OFF; SET VERIFY OFF; SET LINESIZE 2000; SET... (2 Replies)
Discussion started by: Kevin Tivoli
2 Replies

2. Shell Programming and Scripting

Problem in formatting output of SQL query in excel sheet in shell script

Hi Guys.. Need your help to format the output of my shell script. I am using spool command to take out put in csv file. below is my code. (for example) col USERNAME for a15 col EMAIL for a30 col FULL_NAME for a20 col LAST_LOGIN for a40 col DATE_CREATED for a40 SPOOL 120.csv... (3 Replies)
Discussion started by: Agupte
3 Replies

3. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

4. Shell Programming and Scripting

Formatting the query output using shell script

Hi All, I'm finding it difficult to format the query output that was returned in a shell script. Actually i have one shell script which does some DB stuff and depending on the result it will do some more tasks. My question here is to format the query output returned by mysql. Intitally my... (5 Replies)
Discussion started by: RSC1985
5 Replies

5. Shell Programming and Scripting

Total noob script

Hi i am a total noob at shell scripting. i was wondering if somebody could help me with my script. i want the script to search the dev folder for the burner file because they are different between distrubutions? as i under stand it. this i the script. #!/bin/bash echo "Script för att bränna 360... (4 Replies)
Discussion started by: MatsO
4 Replies

6. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

7. Shell Programming and Scripting

Noob needs script help Grep

while read s1 s2; do grep -i -w $s1 6-29data | tr "" "" | sed 's/^*,//' | sed 's/200906/2009-06-/g' >> $s1.txt ; cat header > here ; cat $s1.txt | sort | uniq | tac >> here ; cat here | uniq > $s1.txt ; done < list Wow this almost worked file list has 8000 stock symbols which are... (4 Replies)
Discussion started by: harte
4 Replies

8. Shell Programming and Scripting

noob. need help to create a script.

Hi All. im a noob to scripting. could somone help me with a script please. what i want to do is. 1. run a cmd in the script - qmqtool -s this will give me an output similar to this. Messages in local queue: 790 Messages in remote queue: 306 Messages in todo queue: 23 i then want... (1 Reply)
Discussion started by: aron
1 Replies

9. Shell Programming and Scripting

sed formatting query

had asked this earlier , but now with some small modification. i wish to remove "#" characters and replace them with a single # character. how to do that? . like # should be appended in all lines ex if the file is like ####aasd ##pqr #qwert poppy output shud be #aasd #pqr #qwert... (2 Replies)
Discussion started by: gopsman
2 Replies

10. Shell Programming and Scripting

sed formatting query

hi i have to modify a number accross a file for example in the following file name - abc age 20 name - def age 25 name - pqr age 54 name - xyz age 32 i want the number against all age to be say 50. like this name - abc age 50 name - def (2 Replies)
Discussion started by: gopsman
2 Replies
Login or Register to Ask a Question