![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| arithmetic operation on two columns | Jenny.palmy | UNIX for Dummies Questions & Answers | 1 | 05-04-2008 03:08 AM |
| Can I use wc -l with arithmetic expression? | lalelle | Shell Programming and Scripting | 3 | 08-11-2007 03:44 PM |
| arithmetic in ksh | amon | Shell Programming and Scripting | 12 | 02-04-2007 10:43 PM |
| Arithmetic In UNIX | tygun | UNIX for Dummies Questions & Answers | 3 | 11-23-2005 01:46 PM |
| Simple arithmetic operation | paladyn_2002 | Shell Programming and Scripting | 2 | 04-19-2004 12:09 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Help with arithmetic operation
I am using egrep to extract numbers from a file and storing them as variables in a script. But I am not able to do any arithmetic operations on the variables using "expr" because it stores them as char and not integers. Here is my code and the error I get. Any help will be appreciated.
#!/bin/sh $x=`egrep "string" filename | grep -oE "[[:digit:]]{1,}"` $y=`egrep "string" filename | grep -oE "[[:digit:]]{1,}"` c=`expr $x + $y` Error: expr: non-numeric argument |
| Forum Sponsor | ||
|
|
|
|||
|
i used perl to solve the problem i had. thanks.
#!/usr/bin/perl $n = `egrep -n "string" filename | egrep -o "[[:digit:]]{1,}" | sed q`; $m = `egrep -n "string" filename | egrep -o "[[:digit:]]{1,}" | sed q`; $c= $m - $n; print $c |