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
calculate the space za_7565 Shell Programming and Scripting 8 05-04-2008 04:22 AM
how to calculate CPU time under HP-UX limame HP-UX 1 06-18-2007 02:28 PM
How To Calculate krishna_sicsr Shell Programming and Scripting 1 03-28-2007 07:24 AM
How to calculate with awk whatisthis Shell Programming and Scripting 4 11-09-2005 08:39 AM
bc calculate problem Nicol UNIX for Dummies Questions & Answers 2 09-13-2004 07:21 AM

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

Join Date: Jan 2006
Posts: 71
calculate output

I was wondering can anyone give me a clue how to start script which would do the following:

I have 2 numbers as input for example: 100 and 1000 and I need to create file and in that file should be written

100 - 199

200 - 299

300 - 399

400 - 499

500 - 599

600 - 699

700 - 799

800 - 899

900 - 999


U can guess if I have 100 as a number and 100 000 as b number how would it like...
should I start with awk or...

thanks in advance...
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-12-2006
Registered User
 

Join Date: Mar 2006
Location: Gurgaon
Posts: 26
Input 1- 100
Input 2 -1000
hope thats what u wanna do....

#! /bin/ksh
typeset -i ranger=$1
typeset -i mark=$2
typeset -i range=`expr $ranger - 1`
while [[ $ranger -lt $mark ]]
do
echo "$ranger "-" `expr $ranger + $range`"
ranger=`expr $ranger + $range`
ranger=`expr $ranger + 1`
done
Reply With Quote
  #3 (permalink)  
Old 04-12-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,473
Code:
#! /usr/bin/ksh

if [ $# -ne 2 ]
then
  echo "<script> first second"
  exit 1
fi

first=$1
second=$2
INTERVAL=$1
while [ $first -lt $second ]
do
  echo "$first---$(($first + $INTERVAL - 1))"
  first=$(($first + $INTERVAL))
done

exit 0
Reply With Quote
  #4 (permalink)  
Old 04-12-2006
Registered User
 

Join Date: Jan 2006
Posts: 71
Thank to both of U...I am beginner in shell programming but I figure how scripts work...

THANKS again
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:32 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