RabbieBurns Posted June 30, 2012 Posted June 30, 2012 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: #!/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?
RabbieBurns Posted June 30, 2012 Author Posted June 30, 2012 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...
Steve21 Posted June 30, 2012 Posted June 30, 2012 @echo off FOR /L %%A IN (400000000,1,499999999) DO ECHO 0%%A Under cmd, just do: blah.bat > test1.txt ? Should work. Steve 1
Steve21 Posted June 30, 2012 Posted June 30, 2012 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
Steve21 Posted June 30, 2012 Posted June 30, 2012 Out of curiosity, why do you need 100 milllllllion numbers? Steve
RabbieBurns Posted June 30, 2012 Author Posted June 30, 2012 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
RabbieBurns Posted June 30, 2012 Author Posted June 30, 2012 is that how many there are, wow. Might take longer than I thought. They are the mobile phone numbers for this country.
Steve21 Posted June 30, 2012 Posted June 30, 2012 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
Steve21 Posted June 30, 2012 Posted June 30, 2012 *waits a week to see an Aussie telecom company go bust*
Arthur Posted June 30, 2012 Posted June 30, 2012 (edited) Will probably take a while unless you got an epic machine to run it on Only took me 3 minutes 56 seconds. $stream = New-Object System.IO.StreamWriter("C:\Temp\Numbers.txt") for ($i = 400000000; $i -lt 500000000; $i++) { $stream.WriteLine('0' + $i) } $stream.Close() http://i.imgur.com/NCA70.png http://i.imgur.com/QVI1e.png * My PC has a Core i5-2500K @ 4.6GHz, 16GB RAM and a 256GB SSD. Edited June 30, 2012 by Arthur 1
RabbieBurns Posted June 30, 2012 Author Posted June 30, 2012 @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.
Steve21 Posted June 30, 2012 Posted June 30, 2012 (edited) 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 echo "0$i"; etc Or if you want use printf with formatting. Edit - Guess you could just do it like this too: seq -f %09.0f 0 1000000000 Formatting it before output, so should it anyway. Edited June 30, 2012 by Steve21
CyberNerd Posted June 30, 2012 Posted June 30, 2012 @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?
Arthur Posted June 30, 2012 Posted June 30, 2012 (edited) is there any way for it to add the preceding 0? Updated script in post #13. Edited June 30, 2012 by Arthur 1
Steve21 Posted June 30, 2012 Posted June 30, 2012 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
CyberNerd Posted June 30, 2012 Posted June 30, 2012 (edited) 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: !#/usr/bin/python count = 400000000 while count <= 499999999: count = count + 1 print '0%s' % (count) Edited June 30, 2012 by CyberNerd 2
Steve21 Posted June 30, 2012 Posted June 30, 2012 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
CyberNerd Posted June 30, 2012 Posted June 30, 2012 !#/usr/bin/python count = 400000000 while count <= 499999999: count = count + 1 print '0%s' % (count) that took about 3min to run on Intel® Core2 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
RabbieBurns Posted June 30, 2012 Author Posted June 30, 2012 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
Arthur Posted June 30, 2012 Posted June 30, 2012 It wont open in np++ any more Notepad++ won't be able to handle a file that large.
CyberNerd Posted June 30, 2012 Posted June 30, 2012 that took about 3min to run on Intel® Core2 Duo CPU T5870 @ 2.00GHz actually, it takes just over 2min time python ./file > file2 real 2m17.287s user 2m10.026s sys 0m4.393s dos 1 bash 0 python 1 powershell 0
RabbieBurns Posted June 30, 2012 Author Posted June 30, 2012 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:~#
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now