如何使用批处理文件随机重新排列文本文件中的行 [英] How to randomly rearrange lines in a text file using a batch file

查看:155
本文介绍了如何使用批处理文件随机重新排列文本文件中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个随机抽取不同MAC地址的代码,但是不知道该怎么做。我想如何处理这个问题是用这个脚本随机化或重新排列文本文件中MAC地址的顺序,但是我不知道如何用批处理文件来做到这一点。这将如何工作,它会读取maclist.txt,然后创建一个新的临时文件,随机顺序maclist_temp.txt,这将是重新安排的文件。然后,它将按顺序拉这个随机文件。



我试过谷歌和搜索网络,但我没有发现任何有用的东西。我仍然在积极寻找,但任何建议将是非常有用的。

一些简单的提取和删除一个随机行,然后添加到底部可能工作。随机化会更好,但我想保留原来的名单。例如:
$ b $ ol <

  • 创建一个名为maclist_temp.txt的maclist.txt的临时副本

  • 随机MAC地址,将其从maclist_temp.txt中删除

  • 读取到底部

    是我想要的,但任何建议,欢迎。

    解决方案

    您可以试试这个批处理文件,以帮助您洗牌 maclist.txt 。批处理代码的用法是:

      C:\>键入list.txt | shuffle.bat> maclist_temp.txt 

    发出此命令后, maclist_temp.txt 将包含一个随机的MAC地址列表。



    希望这有助于。


    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:

    1. Make a temp copy of maclist.txt called maclist_temp.txt
    2. Take one random MAC address, remove it from maclist_temp.txt
    3. Readd it to the bottom

    That is all I want, but any suggestions are welcome.

    解决方案

    You may try this batch file to help you to shuffle your maclist.txt. The usage of the batch code is

    C:\> type list.txt | shuffle.bat > maclist_temp.txt
    

    After issuing this command, maclist_temp.txt will contain a randomized list of MAC address.

    Hope this helps.

    这篇关于如何使用批处理文件随机重新排列文本文件中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆