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\nor\nif you deal with UNIX files
-
And, here is your expected OUTPUT text :
Sports –> Football –>Tennis –>Golf People –>Man –>Woman –>ChildBest 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\nor\nif you deal with UNIX files
-
BR
guy038
-
-
T Terry R referenced this topic on
-
This post is deleted!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login