02-22-2012
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=$[$timeTot+$timeTmp] #This is line 28
echo "total RunTime=" $timeTot
this is the error msg:
./ids2.sh: line 28: 0+1.35: syntax error: invalid arithmetic operator (error token is ".35")
total RunTime= 0
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello
Does the unix korn shell provide a function to convert between number and string data-types
regards
Hrishy (1 Reply)
Discussion started by: xiamin
1 Replies
2. Shell Programming and Scripting
I've searched the forum and google, but can't see an answer to this simple problem. Here's my small test script:
#!/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... (4 Replies)
Discussion started by: tpatput
4 Replies
3. Shell Programming and Scripting
Hi,
Im new to shell scripting. My task is to convert shell script feed into html, so basically I have a lot of information in shell script and I want to convert it html. I know you can simply convert the information by hand, but is there any simpler way? Thank you
Dave (3 Replies)
Discussion started by: davwel
3 Replies
4. Shell Programming and Scripting
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
Hi,
Can anyone help me out to check whether the input argument is number?
Example:
REQUEST_ID="123456"
I need to check the REQUEST_ID value is number or string.
Thanks in Advance
Regards
BS (6 Replies)
Discussion started by: balajiora
6 Replies
6. Shell Programming and Scripting
Hi,
I have a log file, where i am required to identify the line number, where a particular string/line appears in the log file.
And then copy 200 lines above that line number to a new file.
Can someone provide pointers on how to write this script or what command to be used ?
Any... (2 Replies)
Discussion started by: kk2202
2 Replies
7. Shell Programming and Scripting
:confused:Please I really need help with an assignment question. I need to write a script that will take the input from a file and convert the number from Centigrade(Celcius) to Fahrenheit or vice versa. Thank you so much. I really need it to be detailed. Please remember the input comes from a file. (1 Reply)
Discussion started by: starter101
1 Replies
8. Shell Programming and Scripting
I have a script which converts rows to columns.
file_name=$1
mailid=$2
#CREATE BACKUP OF ORIGINAL FILE
#cp ${file_name}.xlsx ${file_name}_temp.xlsx
#tr '\t' '|' < ${file_name}_temp.xlsx > ${file_name}_temp.csv
#rm ${file_name}_temp.xlsx
pivot_row=`head -1 ${file_name}`
sed 1d... (3 Replies)
Discussion started by: andy538
3 Replies
9. Shell Programming and Scripting
Hi I am new in programming.
I have written a shell code, but i want to secure my code.
I have tried SHC. It is converting it to binary, but can be converted in plain text again by core dump.
I have tried to convert it in rpm by "rpmbuild -bb my.spec" option but the result is same.
... (4 Replies)
Discussion started by: Priy
4 Replies
10. UNIX for Beginners Questions & Answers
I have below code inside my awk script
if ( $0 ~ /SVC IN:/ )
{
svc_in=substr( $0,23 , 3);
if (msg_start == 1 && msg_end == 0)
{
msg_arr=$0;
}
}
else if ( $0 ~ /^SVC OUT:/ )
{
svc_out=substr( $0, 9, 3);
if (msg_start == 1 && msg_end == 0)
... (6 Replies)
Discussion started by: bhagya123
6 Replies
LEARN ABOUT OSX
xs::apitest::keywordrpn
XS::APItest::KeywordRPN(3pm) Perl Programmers Reference Guide XS::APItest::KeywordRPN(3pm)
NAME
XS::APItest::KeywordRPN - write arithmetic expressions in RPN
SYNOPSIS
use XS::APItest::KeywordRPN qw(rpn calcrpn);
$triangle = rpn($n $n 1 + * 2 /);
calcrpn $triangle { $n $n 1 + * 2 / }
DESCRIPTION
This module supplies plugged-in keywords, using the new mechanism in Perl 5.11.2, that allow arithmetic to be expressed in reverse Polish
notation, in an otherwise Perl program. This module has serious limitations and is not intended for real use: its purpose is only to test
the keyword plugin mechanism. For that purpose it is part of the Perl core source distribution, and is not meant to be installed.
RPN expression syntax
Tokens of an RPN expression may be separated by whitespace, but such separation is usually not required. It is required only where
unseparated tokens would look like a longer token. For example, "12 34 +" can be written as "12 34+", but not as "1234 +".
An RPN expression may be any of:
1234
A sequence of digits is an unsigned decimal literal number.
$foo
An alphanumeric name preceded by dollar sign refers to a Perl scalar variable. Only variables declared with "my" or "state" are
supported. If the variable's value is not a native integer, it will be converted to an integer, by Perl's usual mechanisms, at the
time it is evaluated.
A B "+"
Sum of A and B.
A B "-"
Difference of A and B, the result of subtracting B from A.
A B "*"
Product of A and B.
A B "/"
Quotient when A is divided by B, rounded towards zero. Division by zero generates an exception.
A B "%"
Remainder when A is divided by B with the quotient rounded towards zero. Division by zero generates an exception.
Because the arithmetic operators all have fixed arity and are postfixed, there is no need for operator precedence, nor for a grouping
operator to override precedence. This is half of the point of RPN.
An RPN expression can also be interpreted in another way, as a sequence of operations on a stack, one operation per token. A literal or
variable token pushes a value onto the stack. A binary operator pulls two items off the stack, performs a calculation with them, and
pushes the result back onto the stack. The stack starts out empty, and at the end of the expression there must be exactly one value left
on the stack.
OPERATORS
These are the operators being added to the Perl language.
rpn(EXPRESSION)
This construct is a Perl expression. EXPRESSION must be an RPN arithmetic expression, as described above. The RPN expression is
evaluated, and its value is returned as the value of the Perl expression.
calcrpn VARIABLE { EXPRESSION }
This construct is a complete Perl statement. (No semicolon should follow the closing brace.) VARIABLE must be a Perl scalar "my"
variable, and EXPRESSION must be an RPN arithmetic expression as described above. The RPN expression is evaluated, and its value is
assigned to the variable.
BUGS
This module only performs arithmetic on native integers, and only a small subset of the arithmetic operations that Perl offers. This is
due to it being intended only for demonstration and test purposes.
The RPN parser is liable to leak memory when a parse error occurs. It doesn't leak on success, however.
SEE ALSO
Devel::Declare, "PL_keyword_plugin" in perlapi
AUTHOR
Andrew Main (Zefram) <zefram@fysh.org>
COPYRIGHT
Copyright (C) 2009 Andrew Main (Zefram) <zefram@fysh.org>
LICENSE
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.12.5 2012-11-03 XS::APItest::KeywordRPN(3pm)