Sort lines but keep the hierarchy
-
Hi,
I hope someone can help me with this. I’m looking for a way for this:
People
–>Man
–>Woman
–>Child
Sports
–> Football
–>Tennis
–>GolfTo sort and become like this:
Sports
–> Football
–>Tennis
–>Golf
People
–>Man
–>Woman
–>ChildThank you.
-
Hello, @rune-egenes and All,
Well, not difficult to achieve with regular expressions !
So we start with this INPUT text :
People –>Man –>Woman –>Child Sports –> Football –>Tennis –>Golf
-
Firstly, perform the following regex S/R, with displays all header strings in consecutive lines :
-
SEARCH
\R(?=\x{2013}>)
-
REPLACE
Leave EMPTY
-
And we get the temporary text, below :
People–>Man–>Woman–>Child Sports–> Football–>Tennis–>Golf
- Secondly, run the option
Edit > Line Operations > Sort Lines Lexicographically Descending
After the sort operation, we get :
Sports–> Football–>Tennis–>Golf People–>Man–>Woman–>Child
-
Thirdly, execute this last regex S/R, below :
-
SEARCH
(?=\x{2013}>)
-
REPLACE
\r\n
or\n
if you deal with UNIX files
-
And, here is your expected OUTPUT text :
Sports –> Football –>Tennis –>Golf People –>Man –>Woman –>Child
Best Regards
guy038
-
-
@guy038 Thank you so much. I also have some lists that need to be sorted where
-> is tab (\t) is there a regex for that? Thank you -
Hi, @rune-egenes and All,
Easy !
-
First regex :
-
SEARCH
\R(?=\t)
-
REPLACE
Leave EMPTY
-
-
Sort
-
Second regex
-
SEARCH
(?=\t)
-
REPLACE
\r\n
or\n
if you deal with UNIX files
-
BR
guy038
-
-
-
This post is deleted!