0

I have a text file which contains filenames with their extension.

apple.c
orange.hpp
plum.h
mango.c
banana.cpp
grapes.hpp

I want the above text sorted alphabetically but grouped based on their extensions: i.e,

apple.c
mango.c
banana.cpp
plum.h
grapes.hpp
orange.hpp

How can I do this in Notepad++?

I tried the TextFX plugin, Linesort Plugin and column editor. Linesort plugin has an option to sort lines from right but the output is still not correct.

2 Answers 2

2

There is a plugin ‘SQL’. It requires a header to be used properly. I've added the header so the text now looks as follows

COLUMN1.COLUMN2
apple.c
orange.hpp
plum.h
mango.c
banana.cpp
grapes.hpp

Choose N++ Menu --> Plugins --> SQL --> Start

SQL statement: SELECT COLUMN1 c1,COLUMN2 c2 FROM data ORDER BY c2,c1
Delimiter: .

Click on 'execute SQL' button.

A new file will be created with this content:

SQL Plugin 1.0.1025
Query         : select column1 c1,column2 c2 from data order by c2,c1
Sourcefile    : new 6
Delimiter     : .
Number of hits: 6
===================================================================================
Query result:
apple.c
mango.c
banana.cpp
plum.h
grapes.hpp
orange.hpp
1

Besides non-standard plugins, there is also way using standard TextFX plugin which many users find shipped with their N++. It is not amazingly elegant, but it works:

apple.c
orange.hpp
plum.h
mango.c
banana.cpp
grapes.hpp
  1. Use find/replace to prepend extensions before file names
  • Find what: ^(.*\.(.*))$
  • Replace with: \2\t\1
  • Search mode: Regular Expression
  • ". matches newline": Unchecked
c   apple.c
hpp orange.hpp
h   plum.h
c   mango.c
cpp banana.cpp
hpp grapes.hpp
  1. Edit → Line Operations → Sort
c   apple.c
c   mango.c
cpp banana.cpp
h   plum.h
hpp grapes.hpp
hpp orange.hpp
  1. Use find/replace to remove temporary column
  • Find what: ^.*\t(.*)$
  • Replace with: \1
  • Search mode: Regular Expression
  • ". matches newline": Unchecked
apple.c
mango.c
banana.cpp
plum.h
grapes.hpp
orange.hpp
3
  • You can use Edit → Line Operations → Sort instead of TextFX.
    – root
    Jun 12, 2023 at 0:29
  • @root – sure, this answer is now obsolete. TextFX is no longer viable and continually, the Edit menu was enhanced with sorting abilities.
    – miroxlav
    Jun 13, 2023 at 9:47
  • I suggested an edit to make the answer valid again. The edit is being reviewed.
    – root
    Jun 13, 2023 at 21:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .