Sequential numbers

Hi All,
I am looking for a simple way to write numbers to a file sequentially starting from 1 and ending on a specified upper limit. Example of the output file is below

Example

1
2
3
4
5
.
.
.
.
1000

please let me know the best way to do it.

Is it just me or has the world become too lazy? I'm sure with 115 posts to your name you must have come across the famous for loop, available in a language of your choosing.

many ways to skin your cat...

e.g. bash:

#  echo {1..1000}|tr " " "\n">file

using while loop ..

$ i=1; while [ $i -le 100 ]; do echo $i; i=$((i+1)); done

On Linux box, you can use the seq command :

$ seq 5
1
2
3
4
5
$ seq 2 5
2
3
4
5
$ seq 1 2 10
1
3
5
7
9
$

Jean-Pierre.

Hi.

On Linux and other platforms, e.g. freebsd:

vm-freebsd ~ % version =o
OS, ker|rel, machine: FreeBSD, 8.0-RELEASE, i386
vm-freebsd ~ % jot 5 11
11
12
13
14
15

cheers, drl

just another awk ...

awk 'BEGIN{ while (++x<=10)print x; exit}'

Just for fun:

awk '($0=NR)>c{exit}1' c=1000 RS='\000' /dev/zero

@Scruti, you geek

lol :smiley:

... by the way, i tested you code in an ubuntu 11 that runs in a VirtualBox, see what i got :

$ awk '($0=NR)>c{exit}1' c=1000 RS='\000' /dev/zero
Processus arr�t�
$ ^C
$ ^C
$ 

It went into an endless loop, i had to ^C and then wait for 1 minutes before it could break it and give me the prompt back !

:slight_smile:

@ctsgnb, hehe could not resist :o .The trouble is with RS in [^g]awk , so I think we need to revert to this:

tr '\000' '\n' < /dev/zero | awk '($0=NR)>c{exit}1' c=1000

:wink:

@Scruti

Yup ! I've just tested it, this code with tr works fine :wink: