+ Post New Thread
Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 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; Originally Posted by RabbieBurns @ Arthur thanks for the poweshell method also, but is there any way for it to ...
  1. #16


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    340
    Quote Originally Posted by RabbieBurns View Post
    @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.

    from man seq:
    -w, --equal-width
    equalize width by padding with leading zeroes

    not sure why it crashes, perhaps seq can't deal with so many numbers?

  2. #17


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,637
    Thank Post
    250
    Thanked 2,910 Times in 2,142 Posts
    Rep Power
    830
    Quote Originally Posted by RabbieBurns View Post
    is there any way for it to add the preceding 0?
    Updated script in post #13.
    Last edited by Arthur; 30th June 2012 at 05:46 PM.

  3. Thanks to Arthur from:

    RabbieBurns (30th June 2012)

  4. #18

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,762
    Thank Post
    354
    Thanked 533 Times in 498 Posts
    Rep Power
    182
    Quote Originally Posted by CyberNerd View Post
    from man seq:
    -w, --equal-width
    equalize width by padding with leading zeroes

    not sure why it crashes, perhaps seq can't deal with so many numbers?
    Equal width wouldn't affect it. (I think anyway)

    THat's for use with different sizes,

    e.g. 1 and 100 because 001 100

    As the numbers he has are same size it wouldn't change them

    Steve

  5. #19


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    340
    Quote Originally Posted by Steve21 View Post
    Equal width wouldn't affect it. (I think anyway)

    THat's for use with different sizes,

    e.g. 1 and 100 because 001 100

    As the numbers he has are same size it wouldn't change them

    Steve

    I just did:
    seq -w 0400 0499
    and it seemed ok

    you could also do:
    Code:
    !#/usr/bin/python
    count = 400000000
    while count <= 499999999:
           count = count + 1
           print '0%s' % (count)
    Last edited by CyberNerd; 30th June 2012 at 08:24 PM.

  6. 2 Thanks to CyberNerd:

    RabbieBurns (30th June 2012), Steve21 (30th June 2012)

  7. #20

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,762
    Thank Post
    354
    Thanked 533 Times in 498 Posts
    Rep Power
    182
    Quote Originally Posted by CyberNerd View Post
    I just did:
    seq -w 0400 0499
    and it seemed ok
    Ah fair enough, maybe it does it different as you already used the following 0s Didn't like it for me!

    Steve

  8. #21


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    340
    Quote Originally Posted by CyberNerd View Post
    !#/usr/bin/python
    count = 400000000
    while count <= 499999999:
    count = count + 1
    print '0%s' % (count)
    that took about 3min to run on Intel(R) Core(TM)2 Duo CPU T5870 @ 2.00GHz


    tail file2
    0499999991
    0499999992
    0499999993
    0499999994
    0499999995
    0499999996
    0499999997
    0499999998
    0499999999
    0500000000


    ls -lh file2
    -rw-rw-r--. 1 cybernerd cybernerd 1.1G Jun 30 17:06 file2

  9. #22

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,532
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    this is either a quad core or its dualcore with hyperthreading but it seems i have 4 cpus

    task manager shows cmd.exe isnt using more than 12%

    Ill try it in python later see if it will run faster but im guessing its nearly done. It wont open in np++ any more

  10. #23


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,637
    Thank Post
    250
    Thanked 2,910 Times in 2,142 Posts
    Rep Power
    830
    Quote Originally Posted by RabbieBurns View Post
    It wont open in np++ any more
    Notepad++ won't be able to handle a file that large.

  11. #24


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    340
    Quote Originally Posted by CyberNerd View Post
    that took about 3min to run on Intel(R) Core(TM)2 Duo CPU T5870 @ 2.00GHz
    actually, it takes just over 2min

    time python ./file > file2

    real 2m17.287s
    user 2m10.026s
    sys 0m4.393s


    Quote Originally Posted by RabbieBurns View Post
    dos 1 bash 0
    python 1 powershell 0

  12. #25

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,532
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    I cant get the python one to work, it just displays 50000000 for me..

    root@ubuntu:~# ./test.py
    0500000000
    root@ubuntu:~# cat test.py
    #!/usr/bin/python
    count = 400000000
    while count <= 499999999:
    count = count + 1
    print '0%s' % (count)
    root@ubuntu:~#

  13. #26

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,762
    Thank Post
    354
    Thanked 533 Times in 498 Posts
    Rep Power
    182
    You're running it directly, not outputting it? Will only show end result I'd assume?

    Steve

  14. #27

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,532
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    but it takes <20 sec to display the 50000000 it cant possibly iterate them all in that time

    root@ubuntu:~# time ./test.py
    0500000000

    real 0m13.115s
    user 0m12.870s
    sys 0m0.020s

    also >> to a file oinly shows the 1 line

  15. #28

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,532
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    thats the dos batch file just finished :P

  16. #29


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,637
    Thank Post
    250
    Thanked 2,910 Times in 2,142 Posts
    Rep Power
    830
    Quote Originally Posted by CyberNerd View Post
    python 1 powershell 0
    On this occasion it looks like it's the opposite result.

  17. #30

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,532
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    1.2GB text file compresses into a 13MB rar file.. wow.



SHARE:
+ Post New Thread
Page 2 of 4 FirstFirst 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, 07:44 PM
  2. terminal script to create home dirs in OS X
    By HodgeHi in forum Coding
    Replies: 6
    Last Post: 3rd July 2009, 11:13 AM
  3. Replies: 6
    Last Post: 16th September 2006, 10:33 PM
  4. Script to change user email in AD (or Exchange)
    By SpuffMonkey in forum Scripts
    Replies: 16
    Last Post: 8th November 2005, 11:31 PM
  5. Script to shut down computers in a certain OU
    By tosca925 in forum Scripts
    Replies: 11
    Last Post: 25th September 2005, 10: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
  •