Sponsored Content
Top Forums Shell Programming and Scripting how to add integer with expr? Post 302310856 by mingming88 on Monday 27th of April 2009 08:36:44 AM
Old 04-27-2009
how to add integer with expr?

i got a file called Marks
The format of Marks is:

12345678 5 7
23456789 7 9 3

What can i do with a loop, read expr and echo command to produce a new file like below:

12345678:12
23456789:20

and also when we adding fewer than 3 value with expr, we need to change any null value for variable to 0 so expr gets a valid argument. how can i change it?

So how can i produce a new file with the format above? Using Bourne Shel script.
Thank you for your helping!!Smilie

Last edited by mingming88; 04-27-2009 at 10:21 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help: How do I ADD non-integer (decimal) values?

I am trying to create a script that will read from a file two non-integer values (decimals) and add those values together. For example, I want to add 1.51 and -2.37 together and get the sum. Any ideas? Thanks! (2 Replies)
Discussion started by: limshady411
2 Replies

2. UNIX for Dummies Questions & Answers

Add comma to integer using AWK

Srr for being pain her let say i have a data in a file like this 1@1000 2@2000 4@4000 5@7770 6@8998 7@80008 i am a newbie in Unix i need to add a comma to integer using AWK function. for example, 1,000 or 80,008 how can i do that ps. i'm using bash shell (1 Reply)
Discussion started by: Nutter
1 Replies

3. Shell Programming and Scripting

expr: Integer argument too large

Hi all, In KSH, I have got an error message like, "expr: Integer argument too large" I received this error message when I mutiply two large values and displaying the resultant output. Is there any other altenative way to go with too large values? Kindly let me know asap... Thanks in... (12 Replies)
Discussion started by: iamgeethuj
12 Replies

4. Shell Programming and Scripting

using expr command to add value from two file

How to add two number from two different file using expr command ?? (3 Replies)
Discussion started by: aliahsan81
3 Replies

5. Shell Programming and Scripting

how to convert string to an integer and how to do calculations like add.,sub.,mult. on it

How to convert string into an integer or number For example : % set tim = `date` % echo $tim Tue Feb 22 16:25:08 IST 2011 here How to increment time by 10 hrs like 16+10 , here 16 is a string in date cmd. .. how to convert 16 to an integer and added to a another nimber ? Thanks... (3 Replies)
Discussion started by: sbhamidi
3 Replies

6. Shell Programming and Scripting

Non-integer argument in expr

i wrote this simple shell script #!/bin/bash read N1 read N2 expr $N1 + $N2 it work fine in bash and i add it on xinetd for some test but when i try to use in with telnet i got this error : ehsan@debian:~$ telnet 192.168.1.4 1234 Trying 192.168.1.4... Connected to 192.168.1.4.... (14 Replies)
Discussion started by: niasha
14 Replies

7. Shell Programming and Scripting

expr: An integer value was expected

Hi, I am trying to execute a simple script as below to compare a value from a file and copy that line based on a condition. while read line do code_check = `expr substr "$line" 6 1` if ; then echo "${line}" >> /temp/bill/push_updated.dat else echo "line ignored" fi done <... (8 Replies)
Discussion started by: ramkiran77
8 Replies

8. Shell Programming and Scripting

Getting error in bash script; expr $a + 1: integer expression expected

Hi, I am new to shell/bash script. I am trying to run below script #!/bin/bash a=0 b=10 if then echo "a is equal to be" else echo "a is not equal to be" fi MAX=10 while do echo $a a='expr $a + 1' done (1 Reply)
Discussion started by: Mallikgm
1 Replies

9. Shell Programming and Scripting

Expr: non-integer argument

This is my code.... It works correct, but does not work with 4 and 5. My program is about finding average. so when i run 4 5 it gives me error "expr: non-integer argument". But when i say sh average 45 67 it works. Whats wrong?how to fix it? sum=0 n=0 if then for i in $* do if ... (2 Replies)
Discussion started by: Natalie
2 Replies

10. UNIX for Dummies Questions & Answers

awk to add/subtract an integer to/from each entry in columns?

---------- Post updated at 01:58 PM ---------- Previous update was at 01:48 PM ---------- For some reason my question is not getting printed. Here are the details: Greetings. I would like to add/subtact an integer to/from two columns of integers. I feel like this should be easy using awk... (3 Replies)
Discussion started by: Twinklefingers
3 Replies
fmlexpr(1F)							   FMLI Commands						       fmlexpr(1F)

NAME
fmlexpr - evaluate arguments as an expression SYNOPSIS
fmlexpr arguments DESCRIPTION
The fmlexpr function evaluates its arguments as an expression. After evaluation, the result is written on the standard output. Terms of the expression must be separated by blanks. Characters special to FMLI must be escaped. Note that 30 is returned to indicate a zero value, rather than the null string. Strings containing blanks or other special characters should be quoted. Integer-valued arguments may be pre- ceded by a unary minus sign. Internally, integers are treated as 32-bit, 2s complement numbers. The operators and keywords are listed below. Characters that need to be escaped are preceded by . The list is in order of increasing precedence, with equal precedence operators grouped within {} symbols. USAGE
Expressions expr | expr Returns the first expr if it is neither NULL nor 0, otherwise returns the second expr. expr & expr Returns the first expr if neither expr is NULL or 0, otherwise returns 0. expr { =, >, >=, <, <=, != } expr Returns the result of an integer comparison if both arguments are integers, otherwise returns the result of a lexical comparison. expr { +, - } expr Addition or subtraction of integer-valued arguments. expr { *, /, % } expr Multiplication, division, or remainder of the integer-valued arguments. expr : expr The matching operator : (colon) compares the first argument with the second argument which must be a regular expression. Regular expression syntax is the same as that of ed(1), except that all patterns are "anchored" (that is, begin with ^) and, therefore, ^ is not a special character, in that context. Normally, the matching operator returns the number of bytes matched (0 on failure). Alterna- tively, the (...) pattern symbols can be used to return a portion of the first argument. EXAMPLES
Example 1 Incrementing a variable Add 1 to the variable a: example% fmlexpr $a + 1 | set -l a Example 2 Setting a variable equal to a filename For $a equal to either /usr/abc/file or just file: example% fmlexpr $a : .*/(.*) | $a returns the last segment of a path name (that is, file). Watch out for / alone as an argument: fmlexpr will take it as the division opera- tor (see NOTES below). Example 3 A better representation of Example 2 example% fmlexpr //$a : .*/(.*) The addition of the // characters eliminates any ambiguity about the division operator (because it makes it impossible for the left-hand expression to be interpreted as the division operator), and simplifies the whole expression. Example 4 Counting characters in a variable Return the number of characters in $VAR: example% fmlexpr $VAR : .* EXIT STATUS
As a side effect of expression evaluation, fmlexpr returns the following exit values: 0 if the expression is neither NULL nor 0 (that is, TRUE) 1 if the expression is NULL or 0 (that is, FALSE) 2 for invalid expressions (that is, FALSE). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
ed(1), expr(1), set(1F), sh(1), attributes(5) DIAGNOSTICS
syntax error for operator/operand errors non-numeric argument if arithmetic is attempted on such a string In the case of syntax errors and non-numeric arguments, an error message will be printed at the current cursor position. Use refresh to redraw the screen. NOTES
After argument processing by FMLI, fmlexpr cannot tell the difference between an operator and an operand except by the value. If $a is an =, the command: example% fmlexpr $a = = looks like: example% fmlexpr = = = as the arguments are passed to fmlexpr (and they will all be taken as the = operator). The following works, and returns TRUE: example% fmlexpr X$a = X= SunOS 5.11 5 Jul 1990 fmlexpr(1F)
All times are GMT -4. The time now is 03:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy