+ Post New Thread
Page 1 of 4 1234 LastLast
Results 1 to 15 of 52
Scripts Thread, script to output every number in a sequence between x and y to a text file in Coding and Web Development; Im trying to output every possible number between x and y to a text file, one on each line. They ...
  1. #1

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    199

    script to output every number in a sequence between x and y to a text file

    Im trying to output every possible number between x and y to a text file, one on each line.

    They all start 04xxxxxxxx so I want 0400000000 -> 0499999999

    I tried in excel and got as far as 0400350000 by dragging down but figured there must be a much faster way to do it?

    So I tried in Bash and came up with this:

    Code:
    #!/bin/bash
    for i in `seq 0400000000  0499999999`;
            do
                    echo $i
            done
    which seems to work but it misses off the first 0. Is there any way to add it in as its running, or to the resultant file after?

  2. #2

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    199
    actually that doesnt work. It worked when i tested from 0400000000 to 0400001000 but running it on the full range it just seems to hang...

  3. #3

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    @echo off
    FOR /L %%A IN (400000000,1,499999999) DO ECHO 0%%A
    Under cmd, just do:

    blah.bat > test1.txt ?



    Should work.

    Steve

  4. Thanks to Steve21 from:

    RabbieBurns (30th June 2012)

  5. #4

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    199
    dos 1 bash 0

    works great

    thanks

  6. #5

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by RabbieBurns View Post
    dos 1 bash 0

    works great

    thanks
    Will probably take a while unless you got an epic machine to run it on Seeing it's huge numbers, but should do what you want in the end.

    Steve

  7. #6

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    199
    this is gonna be a big file!

  8. #7

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Out of curiosity, why do you need 100 milllllllion numbers?

    Steve

  9. #8

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    199
    yeh i should really run it on one of my 16core servers rather than my little dual core laptop..

    ah well ill leave it going overnight see how it gets on

  10. #9

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    199
    is that how many there are, wow. Might take longer than I thought.

    They are the mobile phone numbers for this country.

  11. #10

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by RabbieBurns View Post
    is that how many there are, wow. Might take longer than I thought.

    They are the mobile phone numbers for this country.
    Ah, Unless I miscounted:

    0400,000,000 -> 0499,999,999

    400million to 499 million

    That's a lot of phones! Spam a lot? lol

    Steve

  12. #11

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    199
    just as well im on an unlimited plan

  13. #12

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    *waits a week to see an Aussie telecom company go bust*

  14. #13


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,026
    Thank Post
    231
    Thanked 2,699 Times in 1,994 Posts
    Rep Power
    792
    Quote Originally Posted by Steve21 View Post
    Will probably take a while unless you got an epic machine to run it on
    Only took me 3 minutes 56 seconds.

    Code:
    $stream = New-Object System.IO.StreamWriter("C:\Temp\Numbers.txt")
    
    for ($i = 400000000; $i -lt 500000000; $i++) {
        $stream.WriteLine('0' + $i)
    }
    $stream.Close()




    * My PC has a Core i5-2500K @ 4.6GHz, 16GB RAM and a 256GB SSD.
    Last edited by Arthur; 30th June 2012 at 04:55 PM.

  15. Thanks to Arthur from:

    RabbieBurns (30th June 2012)

  16. #14

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,527
    Thank Post
    1,339
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    199
    @Arthur thanks for the poweshell method also, but is there any way for it to add the preceding 0?

    Also if anyone could correct my bash method I wuoldnt mind knowing how to do it in that too please. I tried while, repeat, etc and couldnt seem to get it.

  17. #15

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,697
    Thank Post
    335
    Thanked 515 Times in 483 Posts
    Rep Power
    179
    Quote Originally Posted by RabbieBurns View Post
    Also if anyone could correct my bash method I wuoldnt mind knowing how to do it in that too please. I tried while, repeat, etc and couldnt seem to get it.
    Short answer, either format outputs to set number of digits with preceeding 0s, or cheat and just echo an extra 0 in front of each

    Code:
     echo "0$i"; etc
    Or if you want use printf with formatting.

    Edit - Guess you could just do it like this too:
    Code:
     seq -f %09.0f 0 1000000000
    Formatting it before output, so should it anyway.
    Last edited by Steve21; 30th June 2012 at 04:37 PM.

SHARE:
+ Post New Thread
Page 1 of 4 1234 LastLast

Similar Threads

  1. Program or Script to add URLS to a URL sets in ISA server.
    By FN-GM in forum Internet Related/Filtering/Firewall
    Replies: 9
    Last Post: 3rd July 2009, 06:44 PM
  2. terminal script to create home dirs in OS X
    By HodgeHi in forum Coding
    Replies: 6
    Last Post: 3rd July 2009, 10:13 AM
  3. Replies: 6
    Last Post: 16th September 2006, 09:33 PM
  4. Script to change user email in AD (or Exchange)
    By SpuffMonkey in forum Scripts
    Replies: 16
    Last Post: 8th November 2005, 10:31 PM
  5. Script to shut down computers in a certain OU
    By tosca925 in forum Scripts
    Replies: 11
    Last Post: 25th September 2005, 09:23 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •