The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-12-2007
emjayshaikh emjayshaikh is offline
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
  #2 (permalink)  
Old 09-13-2007
aajan aajan is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 80
can you provide sample input!!!!!!!!!!!!!!!!!!
  #3 (permalink)  
Old 09-20-2007
emjayshaikh emjayshaikh is offline
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
  #4 (permalink)  
Old 09-23-2007
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
Give more detail

Hi,
Please kindly give more detail of your question.
For example, give us the input and the expected output.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0