![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| arithmetic operation on two columns | Jenny.palmy | UNIX for Dummies Questions & Answers | 1 | 05-04-2008 06:08 AM |
| Can I use wc -l with arithmetic expression? | lalelle | Shell Programming and Scripting | 3 | 08-11-2007 06:44 PM |
| arithmetic in ksh | amon | Shell Programming and Scripting | 12 | 02-05-2007 02:43 AM |
| Arithmetic In UNIX | tygun | UNIX for Dummies Questions & Answers | 3 | 11-23-2005 05:46 PM |
| Simple arithmetic operation | paladyn_2002 | Shell Programming and Scripting | 2 | 04-19-2004 03:09 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|