How to sort a list alphabetically but ignore numbers?

Click For Summary

Discussion Overview

The discussion revolves around sorting a list of URLs alphabetically while ignoring numerical components. Participants explore various methods and tools for achieving this, including programming scripts and command-line utilities.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant suggests using the '/' character as a separator to extract the relevant field for sorting.
  • Another participant mentions the use of awk for parsing and sorting the URLs on a Unix-like system.
  • A different participant references the Right$ function in BASIC for extracting characters from the end of a string.
  • Several participants share a Python script link for sorting URLs, but one notes encountering an error related to file input.
  • A participant questions whether a specific URL would be sorted lexicographically when stripped of certain characters.
  • Clarification is provided regarding how to run the Python script with the necessary input file.

Areas of Agreement / Disagreement

Participants present multiple approaches and tools for sorting URLs, but there is no consensus on a single method or solution. Some methods are challenged or require clarification, indicating ongoing exploration of the topic.

Contextual Notes

Participants express uncertainty regarding the complexity of the URLs and the specific requirements for sorting, which may affect the proposed solutions.

Who May Find This Useful

This discussion may be useful for individuals interested in programming, data processing, or those needing to sort URLs in a specific manner while ignoring numerical values.

rollcast
Messages
403
Reaction score
0
I have a list of urls I need to sort but I need to sort them only using the letters in the url?

Eg.

example.com/174353/a
example.com/3452344/c
example.com/435322/d
example.com/2342/b
example.com/23456/e

Would be sorted as:

example.com/174353/a
example.com/2342/b
example.com/3452344/c
example.com/435322/d
example.com/23456/e

Thanks
AL
 
Computer science news on Phys.org
if you process the file using the / as a separator then you can extract out the 3rd field to sort on.

you could probably use awk to do the parsing to write a new file containing the key then url on one line
then use the sort command to generate a sorted list.

thats if you're running on linux or some unix variant.
 
Most varieties of BASIC have a Right$(,) function, which would read the closing letter(s) off the target string.
 
jedishrfu said:
if you process the file using the / as a separator then you can extract out the 3rd field to sort on.

you could probably use awk to do the parsing to write a new file containing the key then url on one line
then use the sort command to generate a sorted list.

thats if you're running on linux or some unix variant.

I'm on Ubuntu 11.10.

The addresses aren't as simple as I thought here's one for example.

http:// www. flyforums. co.uk/fly-tying-step-step/160-beacon-beige.html

(The spaces are just there to stop it hyperlinking it.)

They all follow the same pattern with a number-couple of keywords separated by -s .html
 
how about this python script

http://snippets.dzone.com/posts/show/10115
 
Last edited by a moderator:
jedishrfu said:
how about this python script

http://snippets.dzone.com/posts/show/10115

It comes up with an error,

" File "sort.py", line 3, in <module>
filename = sys.argv[1]
IndexError: list index out of range"
 
Last edited by a moderator:
Please clarify. Would the URL

http:// www. flyforums. co.uk/fly-tying-step-step/160-beacon-beige.html

be lexicographically sorted with the value

httpwwwflyformscoukflytryingstepstepbeaconbeigehtml

?
 
when you run it you're supposed to provide a file of your urls to be sorted.

./sorturls.py myfileofurls.lst

where sorturls.py is the name of the script and the myfileofurls.lst is your file of unsorted urls.
 

Similar threads

  • · Replies 41 ·
2
Replies
41
Views
6K
Replies
4
Views
3K
  • · Replies 12 ·
Replies
12
Views
1K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 3 ·
Replies
3
Views
1K
Replies
3
Views
2K
Replies
38
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K