0

How do i sort a large text file lines to be all random.

i'm using Emeditor Notepad++

if there a way with Regular Expressions add it too if possible

Small part of example lines:

0
1
3
4
5
6
7
8
9
10
A
a
B
b
C
c
D
d
E
e

Need result:

E
8
e
5
a
c
9
B
1
0
b
7
3
4
A
d
C
D
10
6
3

From what I can gather, neither program has a native line randomization function (much less one that uses regex). However, both have the potential ability to support this kind of function via plugins.

I could not find any pre-made solutions for EmEditor unfortunately but there is a Notepad++ plugin called Python Script which supports another external script that can do basic randomization of lines from within Notepad++.

Regarding the "large" file criteria, Notepad++ may have problems with larger files (though opening a file which is ~500MB is certainly possible without issue). If you do encounter any errors, you may need to split the file into smaller chunks.

Python Script Plugin And RandomizeLines.py

First, download and install the Python Script plugin via the Notepad++ Plugin Manager:

Ex. Python Script Plugin Installation In Notepad++ Plugin Manager

Python Script Plugin In Notepad++ Plugin Manager

Once the plugin is installed, you will need to restart Notepad++. After restarting, the plugin should appear under PluginsPython Script.

Next, download this Python-based "npp-randomizelines" script from Github (Clone or DownloadDownload ZIP). Extract the file and select the RandomizeLines.py file:

Ex. RandomizeLines Master - Extracted

RandomizeLines Master

Copy RandomizeLines.py to your Notepad++PluginsPython ScriptsScripts folder. This may be in a different location than shown depending on your Notepad++ installation.

Ex. RandomizeLines - Notepad++ Plugins Folder

RandomizeLines Script Placement - Notepad++ Plugins Folder

Restart Notepad++ and you should now have a PluginsPython ScriptScriptsRandomizeLines option.

Ex. Running The RandomizeLines Script

RandomizeLines - Running Plugin

With your original input I get the following after running the script:

Ex. Partial Script Results

 B
 a
 c
 b
 4
 A

Notes

  • When run, if no lines are selected, it will randomize all the lines of the currently open file. If individual lines are highlighted, it will only randomize those lines.

  • I haven't played with the Python Script plugin itself, but it's possible that you could extend the script with Python's native regex module. Regarding syntax, the plugin apparently uses a .dll version of Python 2.7.

  • If you want a similar script/plugin for EmEditor, you are probably going to have to code your own using C++. This doesn't seem like a difficult task (at least for anyone even casually familiar with C++ and simple Windows coding) but it is likely more involved than adding regex to the Notepad++ script mentioned above.

  • not that much large max can be 500MB - 1GB txt file but it will be less like work in 10 or 20 millions lines maximum is there a way to do with emeditor because i pref using it and my most usage in emeditor even if there a script or regular expression – DeathRival Sep 21 '17 at 19:56
  • As it regards EmEditor, I am not aware of any solution other than coding your own plugin in C++ to handle this. Notepad++ can handle 500MB files, though larger files may need to be split up. – Anaksunaman Sep 22 '17 at 6:37
  • sadlly this script don't work fine with large files any solution ? – DeathRival Sep 27 '17 at 19:44
  • Not so far as I know for Notepad++ or EmEditor unfortunately. However, if you are willing to try it, I wrote a generic Python script that *should (hopefully) bypass the issues with large files. Basically it shuffles the file lines in batches. If you'd like to try it, you can download it here. It requires Python so there is that. I would use the 3.6.x line. Usage is e.g. shuffle.py filename -chunk 100000 where 100000 is the lines to shuffle in one batch (you can adjust as needed). – Anaksunaman Oct 2 '17 at 6:00
  • Hopefully I tested it well enough and it doesn't suck. =P – Anaksunaman Oct 2 '17 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.