I am creating a code that strips through different MAC addresses randomly, but cannot figure out how to do this. My thought on how to approach this is to randomize or rearrange the order of the MAC address in the text file with this script, but I cannot figure out how to do this with a batch file. How this will work is that it will read "maclist.txt", then create a new temp file with the random order "maclist_temp.txt", that will be the rearranged file. Then, it will pull this randomized file in order.
I have tried Google and searching the web, but I haven't found anything too useful. I'm still actively looking, but any advice would be extremely useful.
Something as simple as extracting and deleting a random line and then adding to the bottom might work. Randomization would be better though, but I want to keep the original list. Something like:
- Make a temp copy of maclist.txt called maclist_temp.txt
- Take one random MAC address, remove it from maclist_temp.txt
- Readd it to the bottom
That is all I want, but any suggestions are welcome.
Here is a simpler method to randomize/randomise a file, no temp files needed. You can even reuse the same input filename.
Limitations are: blank lines and line starting with
;
will be skipped, and lines starting with=
will have all leading=
signs stripped and^
characters are doubled.I really like foxidrive's approach. Nevertheless I want to provide a solution with all the listed limitations eliminated (although
cmd
-related restrictions like file sizes < 2 GiB and line lengths < ~ 8 KiB remain).The key is delayed expansion which needs to be toggled to not lose explamation marks. This solves all the potential problems with special characters like
^
,&
,%
,!
,(
,)
,<
,>
,|
and"
.The counter
index
has been implemented in order not to lose a single line of the original text file, which could happen without, becauserandom
may return duplicate values; withindex
appended, the resulting variable names$$!random!.!index!
are unique.The
findstr /N /R "^"
command precedes every line of the original file with a line number followed by a colon. So no line appears empty to thefor /F
loop which would ignore such. The line number also implicitly solves the issue with leading semicolons, the defaulteol
character offor /F
.Finally, everything up to and including the first colon (remember the said prefix added by
findstr
) is removed from every line before being output, hence no more leading equal-to signs are dismissed.So here is the code:
You may try this batch file to help you to shuffle your
maclist.txt
. The usage of the batch code isAfter issuing this command,
maclist_temp.txt
will contain a randomized list of MAC address.Hope this helps.
Place in cmd file
It spawns a cmd which reads the mac list in the inner for, prefixes a random value and a slash to the mac and sorts the list. Then this list is splitted in the outter for using the slash as delimiter and printing the mac address.
This seems to work. Feed it a command line parameter of the file to randomize.