The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts 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 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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-12-2007
Registered User
 

Join Date: Sep 2007
Posts: 2
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-12-2007
Registered User
 

Join Date: Jun 2007
Posts: 73
can you provide sample input!!!!!!!!!!!!!!!!!!
Reply With Quote
  #3 (permalink)  
Old 09-20-2007
Registered User
 

Join Date: Sep 2007
Posts: 2
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
Reply With Quote
  #4 (permalink)  
Old 09-23-2007
Registered User
 

Join Date: Jun 2007
Posts: 355
Give more detail

Hi,
Please kindly give more detail of your question.
For example, give us the input and the expected output.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0