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

  1. "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.

    enter image description here

  2. Select the text, either lines of text or columns

    • For column mode select - Press and hold Shift+Alt down, select text with the mouse

    enter image description here

  3. "Menu" > "TextFX" > "TextFX Tools" and select one of the following:

    • "Sort lines case sensitive (at column)"

    • "Sort lines case insensitive (at column)"

    enter image description here

  4. Result (before and after):

    enter image description here enter image description here

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

  1. "Menu" > "Plugins" > "Plugin Manager" > "Show Plugin Manager"

  2. Select the "Available"

  3. Select "TextFX Characters"

  4. Click " Install"

Manual install:

  1. Close Notepad++

  2. Download the zip file from http://sourceforge.net/projects/npp-plugins/files/TextFX/TextFX%20v0.26/

  3. Extract to the Notepad++ plugins directory.

  4. Run Notepad++

Solution 2:

Excel solution

This solution will work for any length text after the =

  1. Paste your data into Excel.
  2. Use the formula =MID(A1,FIND("=",A1)+1,LEN(A1)-FIND("=",A1)) to grab everything after the =
  3. Sort on the new column

enter image description here

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:

enter image description here

and after:

enter image description here

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
  1. 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
  1. Use the sort lines feature.

Result:

Alpha#123&name=Alpha&somethingelse
Beta#789&name=Beta&otherstuff
Gamma#456&name=Gamma&differentstuff
  1. 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