Operating System - HP-UX
1828798 Members
2483 Online
109985 Solutions
New Discussion

Re: Shell script to generate sequence number up to 10 million.

 
SOLVED
Go to solution
Gulam Mohiuddin
Regular Advisor

Shell script to generate sequence number up to 10 million.

Hi all,

I need a shell script to create a file with the serial number starting from 1 to 10 million in the following format.

1, XXX, YYY
2, XXX, YYY
3, XXX, YYY
.
.
.
10 million.

We have filesystem with large file enabled, so big flat file shouldn’t be a problem.

Thanks for you anticipated help in advance.

Gulam.
Everyday Learning.
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor

Re: Shell script to generate sequence number up to 10 million.

#!/usr/bin/sh

typeset -i I=1
typeset -i STOP=10000000

while [[ ${I} -le ${STOP} ]]
do
echo "${I},XXX,YYY"
((I += 1))
done

Just redirect stdout to a file and you are done.
If it ain't broke, I can fix that.
Fred Ruffet
Honored Contributor

Re: Shell script to generate sequence number up to 10 million.

#!/bin/sh

count=0
while [ $count -lt 1000000 ]
do
count=$(($count+1))
echo $count >> myFile
done

---

This will create myFile file with sequence 1 to 10000000. I guess it won't need largefiles to be enabled :)

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
H.Merijn Brand (procura
Honored Contributor
Solution

Re: Shell script to generate sequence number up to 10 million.

# perl -le'print"$_,XXX,YYY"for 1..10_000_000' >file

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
baiju_3
Esteemed Contributor

Re: Shell script to generate sequence number up to 10 million.

Stepehneson ,

Can I ask you one thing , what is difference between

typeset var=100
var=100

Thanks
BL.
Good things Just Got better (Plz,not stolen from advertisement -:) )
A. Clay Stephenson
Acclaimed Contributor

Re: Shell script to generate sequence number up to 10 million.

typeset var=100
and
var=100
is not a pericularly good example because the default variable type is string
but

typeset -i var=100
and
var=100

are quite different.

The typeset -i lets the interpreter know that ${i} is an integer value so that optimized arithmatic operations can be done.
Besides, typesetting is simply good discipline. It's especially good in functions because you can now have real local variables that don't conflict with other variables of the same name.
If it ain't broke, I can fix that.