Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

complete number sequences

Status
Not open for further replies.

txolson

IS-IT--Management
Nov 7, 2001
14
US
Hello,
What I am trying to accomplish is to take a 2 column list of numbers and make it into a single column complete list including the numbers that are just referenced by inference in between columns. (Korn, Sed or Awk preferred if possible)
For Example:
303412 303460
303462 30348
303492 303495
------
On the second line the second number is 303480 (the zero is dropped by the system)

SO I would need
303412
303413
303414 (up to 303460)
then continuing on at 303462-303480
then 303492
303493
303494
303495

Hope this makes sense.

Thanks for any ideas.


 
Hi:

One way using ksh (provided I've interpreted correctly what you want):

#/bin/ksh

# no error checking, and the range is in data.file
while read line
do
# set command lne arguments
set - $(echo $line)
f=$1
l=$2
while true
do
if [[ $f -le $l ]]
then
echo $f
f=$((f+1))
else
break
fi

done

done < data.file
 
Sorry, don't know what I was thinking:

#/bin/ksh

# no error checking
while read f l
do
while true
do
if [[ $f -le $l ]]
then
echo $f
f=$((f+1))
else
break
fi

done

done < data.file
 
Or using awk

awk '{for (k=$1;k<=$2;k++) print k}' infile > outfile CaKiwi
 
fine, but....... how do you RIGHT pad the missing '0' of '30348' on the second line? I tried it with awk's 'sprintf', but couldn't get it to do the &quot;right&quot; thing [pun intended].

> On the second line the second number is 303480 (the zero is > dropped by the system) vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 

Oh, right. I should have read it more carefully. What are the rules for dropping a zero? It did not get dropped from the first line. Left zero pad to 6 digits perhaps. Maybe throw in a

for (j=1;j<=2;j++) while (length($i) < 6) $i = $i &quot;0&quot; CaKiwi
 
yeah - I've been trying to do it with the 'sprintf' avoiding the loop - no luck. vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks for the help everyone.
I went with the Korn shell, adding in the check for the dropped zero (It sometimes is also in the first column).

Here's the code:

while read f l
do
while true
do
if [[ ${#f} = 5 ]]; then
f=${f}0
fi
if [[ ${#l} = 5 ]]; then
l=${l}0
fi
if [[ $f -le $l ]]
then
echo $f
f=$((f+1))
else
break
fi

done

done < data.file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top