topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 13, 2024, 5:39 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: Natural line sorting in file  (Read 4905 times)

TucknDar

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,133
    • View Profile
    • Donate to Member
IDEA: Natural line sorting in file
« on: June 22, 2009, 03:23 PM »
Ok, I suppose any decent text editor should be able to sort lines based on alphabet or numbers, but I'm looking for a tool that can sort lines based on Natural order sorting, i.e.

from this:
1. some text
10. yet more text
1011. Text
2. more text again
4. more text
to:
1. some text
2. more text again
4. more text
10. yet more text
1011. Text

No GUI necessary, btw. command line tool would be perfect :)

thanks!

kfitting

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 593
    • View Profile
    • Donate to Member
Re: IDEA: Natural line sorting in file
« Reply #1 on: June 22, 2009, 03:47 PM »
See the following websites for more general info:
http://www.codinghor...archives/001018.html
http://www.codeproje...ralSortComparer.aspx

I've done an algorithm for excel using the Windows API function in XP... someone might be able to use that to simplify things.

Kevin

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: IDEA: Natural line sorting in file
« Reply #2 on: June 23, 2009, 12:25 PM »
No GUI necessary, btw. command line tool would be perfect :)

The Unix "sort -n" command will do this easily. 


skwire@hankoku ~
$ clip
1. some text
10. yet more text
1011. Text
2. more text again
4. more text

skwire@hankoku ~
$ clip | sort -n
1. some text
2. more text again
4. more text
10. yet more text
1011. Text

skwire@hankoku ~

I've attached a Win32 binary version of the Unix sort command.

* sort.zip (30.13 kB - downloaded 330 times.)

TucknDar

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,133
    • View Profile
    • Donate to Member
Re: IDEA: Natural line sorting in file
« Reply #3 on: June 23, 2009, 12:35 PM »
Thanks, skwier, works great :)