Can I sort the text after a certain character?
I have a large list I'm trying to sort but I'd like to sort the list from the value after a certain character. eg:
241&name=A
123&name=C
645&name=B
So I'd like to sort the list alphabetically by "A, B, C" etc. Can I do this in Notepad++ or Excel?
Solution 1:
Notepad++ Solution
-
"Menu" > "TextFX" > "TextFX Tools" and select one of the following:
Clear the check mark for option "+Sort ascending" to sort descending order.
Enable the check mark for option "+Sort ascending" to sort ascending order.
-
Select the text, either lines of text or columns
- For column mode select - Press and hold Shift+Alt down, select text with the mouse
-
"Menu" > "TextFX" > "TextFX Tools" and select one of the following:
"Sort lines case sensitive (at column)"
"Sort lines case insensitive (at column)"
-
Result (before and after):
Notes:
TextFX Tools will sort only the lines you select. If you do a column mode select (Hold Shift + Alt keys down and select text via mouse), then it will sort all the lines that are at least partly selected, but will sort them according to the selected part.
The option "+Sort outputs only UNIQUE (at column) lines" can be checked independent of "+Sort ascending" option (meaning it will work in either ascending or descending mode). When enabled, duplicate entries will be removed when sorting, leaving only unique entries.
When using a rectangular selection, the sort key for a line is the part of that line that is within selection bounds.
Source Sorting lines with plugin TextFX
What if I don't have the TextFX plugin?
Plugin Manager install:
The easiest way to install the plugin is to use the Plugin Manager
"Menu" > "Plugins" > "Plugin Manager" > "Show Plugin Manager"
Select the "Available"
Select "TextFX Characters"
Click " Install"
Manual install:
Close Notepad++
Download the zip file from http://sourceforge.net/projects/npp-plugins/files/TextFX/TextFX%20v0.26/
Extract to the Notepad++
plugins
directory.Run Notepad++
Solution 2:
Excel solution
This solution will work for any length text after the =
- Paste your data into Excel.
- Use the formula
=MID(A1,FIND("=",A1)+1,LEN(A1)-FIND("=",A1))
to grab everything after the=
- Sort on the new column
Solution 3:
With data in column A, in B1 enter:
=RIGHT(A1,1)
and copy down. Then sort cols A and B by B:
Before:
and after:
Solution 4:
There is a different solution with Notepad++ which doesn't require the extra plugin. I used this input and I assumed that there aren't any # in the input. You could just use a different character for separating your sorting item from your original input.
123&name=Alpha&somethingelse
456&name=Gamma&differentstuff
789&name=Beta&otherstuff
-
Use a regular expression search & replace to copy the part you want to sort to the front of the line. Make sure to enable regular expressions and use
Search: (.*)&name=(.*?)&(.*)
Replace: \2#\1&name=\2&\3
Result:
Alpha#123&name=Alpha&somethingelse
Gamma#456&name=Gamma&differentstuff
Beta#789&name=Beta&otherstuff
- Use the sort lines feature.
Result:
Alpha#123&name=Alpha&somethingelse
Beta#789&name=Beta&otherstuff
Gamma#456&name=Gamma&differentstuff
-
Use another regular expression to undo the changes from step 1.
Search: (.*)#(.*)
Replace: \2
Result:
123&name=Alpha&somethingelse
789&name=Beta&otherstuff
456&name=Gamma&differentstuff