How to sort lines in text from 0-9 a-z to all random lines using notepad++ and emeditor

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

Solution 1:


TL;DR

As of Notepad++ v7.9, Notepad++ has a feature called Randomize Line Order which does the same thing as the answer given below (i.e. it randomizes the order of lines in a given document or selection).

It can be accessed with Edit → Line Operations → Randomize Line Order.


Original Answer

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

A screenshot of the Plugin Manager in Notepad++, displaying an alphabetical list of plugin choices. A checkbox is marked to the left of a plugin entry that simply reads Python Script. Below the list is a scrolling textbox displaying general information about the plugin. Below that, there is an Install button in the lower right corner of the manager dialog window. This button starts the download and installation of any marked plugin entries.

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

A screenshot of an extracted file archive called NPP RandomizeLines Master, with two file items. The first file item, titled RandomizeLines.py, is highlighted in the Windows file manager for selection.

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

A screenshot showing an example of where the RandomizeLines Python  script may be located. The full path displayed in the Windows file manager is C, ProgramFiles X 86, Notepad++, plugins, PythonScript, scripts. The RandomizeLines.py Python file is prominently featured residing in this folder.

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

Ex. Running The RandomizeLines Script

A screenshot displaying the Notepad++ menu tree to run the RandomizeLines Python script. The tree shown is the main Notepad++ toolbar menu titled Plugins, a sub menu titled Python Script, a second sub menu titled Scripts, and finally a third sub menu with an entry titled RandomizeLines, used to run that script.

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.