Sponsored Content
Top Forums Shell Programming and Scripting need help converting string to number for calculation Post 302114129 by tpatput on Thursday 12th of April 2007 05:25:15 PM
Old 04-12-2007
need help converting string to number for calculation

I've searched the forum and google, but can't see an answer to this simple problem. Here's my small test script:
Code:
#!/bin/csh
echo "enter a number:"
read num
echo "you entered $num"
set num = `expr $num + 1`
echo new value is $num

can someone show me how to do this calculation? note that in the real life script I'm working on, variables will be input, so something like
Code:
set num = 1

won't work for me

here's an example of the execution
Quote:
sh ./test.sh
enter a number:
12
you entered 12
new value is 12
Thanks in advance for your time and help.
Tom
 

10 More Discussions You Might Find Interesting

1. Programming

converting character string to hex string

HI Hi I have a character string which contains some special characters and I need it to display as a hex string. For example, the sample i/p string: ×¥ïA Å gïÛý and the o/p should be : D7A5EF4100C5010067EFDBFD Any pointers or sample code pls. (5 Replies)
Discussion started by: axes
5 Replies

2. Shell Programming and Scripting

Converting Stirngs to number

I have written a script to compare the values of string (which actually are numbers) but it is not giving the expected output. Please suggest for the script. #!/usr/bin/ksh sysdate=20071009 echo $sysdate currfile=20071008 echo $currfile if ; then echo "Equal" else echo "Not... (2 Replies)
Discussion started by: raman1605
2 Replies

3. Shell Programming and Scripting

Help needed in converting number to bit

Hi, I have the following file input:- 542 4795 61 543 4795 61 544 0 0 545 292 ... (5 Replies)
Discussion started by: ahjiefreak
5 Replies

4. Shell Programming and Scripting

Problem in converting number in shell script

Hi All, I am writing a shell script in which I want to convert a number like : Suppose the number is "98487657" and we have to convert it to "98000000", what I want to do is to retain first 2 digits and convert all remaining digits to "0". Number could be of any length (length... (4 Replies)
Discussion started by: amitanshu.verma
4 Replies

5. Shell Programming and Scripting

Average calculation based on number of rows

Dear users, I need your support, I have a file like this: 272134.548 6680572.715 272134.545 6680572.711 272134.546 6680572.713 272134.548 6680572.706 272134.545 6680572.721 272134.543 6680572.710 272134.544 6680572.715 272134.543 6680572.705 272134.540 6680572.720 272134.544... (10 Replies)
Discussion started by: Gery
10 Replies

6. Shell Programming and Scripting

Performing a calculation on string to be replaced

Hi, I have a file with occurances of the string "TO_DATE(<number here>,'J')" at random places. I need minus 2400000 from the number and replace the string with "convert(date, dateadd(dd, <new number here>,'16 Nov 1858')". I'm finding this difficult as the string isn't necessarily in the... (9 Replies)
Discussion started by: user_invalid
9 Replies

7. Shell Programming and Scripting

KSH SHELL: problem calculation number of lines inside compressed file

Hi Gurus, I am working with a korn shell script to simplify some operations of calculation number of lines inside compressed file. The called function (inside a cycle) is the following: ######################################### # F.ne: CheckCount #########################################... (3 Replies)
Discussion started by: GERMANICO
3 Replies

8. UNIX for Dummies Questions & Answers

converting string to number in shell script

Hi, I am having a problem in converting a string to number so I can preform arithmetic operations. timeTot=0 timeTmp=$(cat idsOutput | grep 'Run time' | cut -c 36-39) timeTot=$ #This is line 28 echo "total RunTime=" $timeTot this is the error msg: ./ids2.sh: line 28: 0+1.35: syntax... (8 Replies)
Discussion started by: turki_00
8 Replies

9. Shell Programming and Scripting

Decimal number calculation problem

I have a below snippet of code from my perl script and its causing a problem when the output of $lTAX is 0 (zero) its getting displayed as -0.00. I want output to be 0 not -0.00. Any help would be appreciated. #!/usr/bin/perl my $lTotA = 50.94; my $lVatA = 8.49; my $lAllocD; my $lAdjNr =... (4 Replies)
Discussion started by: Devesh5683
4 Replies

10. UNIX for Beginners Questions & Answers

Converting negative number to positive in a file

Hi ALL, I am having semi column separated file as below. I am having negative values for the records starting with 11095. How can I convert that positive number I tried this below seems not working sed 's/ \(*\)$/ -\1/;t;s/\(.*\)-/\1/ myfile myfile... (6 Replies)
Discussion started by: arunkumar_mca
6 Replies
TCRTEST(1)							   Tokyo Tyrant 							TCRTEST(1)

NAME
tcrtest - test cases of the remote database API DESCRIPTION
The command `tcrtest' is a utility for facility test and performance test. This command is used in the following format. `host' specifies the host name of the server. `rnum' specifies the number of iterations. tcrtest write [-port num] [-cnum num] [-tout num] [-nr] [-rnd] host rnum Store records with keys of 8 bytes. They change as `00000001', `00000002'... tcrtest read [-port num] [-cnum num] [-tout num] [-mul num] [-rnd] host Retrieve all records of the database above. tcrtest remove [-port num] [-cnum num] [-tout num] [-rnd] host Remove all records of the database above. tcrtest rcat [-port num] [-cnum num] [-tout num] [-shl num] [-dai|-dad] [-ext name] [-xlr|-xlg] host rnum Store records with partway duplicated keys using concatenate mode. tcrtest misc [-port num] [-cnum num] [-tout num] host rnum Perform miscellaneous test of various operations. tcrtest wicked [-port num] [-cnum num] [-tout num] host rnum Perform updating operations of list and map selected at random. tcrtest table [-port num] [-cnum num] [-tout num] [-exp num] host rnum Perform miscellaneous test of the table extension. Options feature the following. -port num : specify the port number. -cnum num : specify the number of connections. -tout num : specify the timeout of each session in seconds. -nr : use the function `tcrdbputnr' instead of `tcrdbput'. -rnd : select keys at random. -mul num : specify the number of records for the mget command. -shl num : use `tcrdbputshl' and specify the width. -dai : use `tcrdbaddint' instead of `tcrdbputcat'. -dad : use `tcrdbadddouble' instead of `tcrdbputcat'. -ext name : call a script language extension function. -xlr : perform record locking. -xlg : perform global locking. -exp num : specify the lifetime of expiration test. If the port number is not more than 0, UNIX domain socket is used and the path of the socket file is specified by the host parameter. This command returns 0 on success, another on failure. SEE ALSO
ttserver(1), ttultest(1), ttulmgr(1), tcrmttest(1), tcrmgr(1), ttutil(3), tcrdb(3) Man Page 2010-01-20 TCRTEST(1)
All times are GMT -4. The time now is 11:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy