User:Digitalme/alphabetize.rb
Appearance
Purpose
[edit]alphabetize.rb can take a list of words, including words that are [[wikilinked]], and alphabetize them. It will sort wikilinks right along with the rest of the words, unlike most alphabetizers, which would just dump the wikilinks at the end.
Use
[edit]$>ruby alphabetize.rb infile outfile
infile is the file you want to alphabetize, outfile is the file you want the alphabetized contents of infile to be outputed into.
The code
[edit]#alphabetize.rb #By digital_me #http://en.wikipedia.org/wiki/User:Digitalme #You may use this script freely, as long as you give me appropriate credit. items = IO.readlines(ARGV[0]) wiki = [] items.each do |word| if word =~ /.*\[\[.*\]\]/ wiki << word word.gsub!("[[" , "") word.gsub!("]]" , "") end end sorted = items.sort sorted.each do |word| if wiki.include?(word) word.insert(1, "[[") word.insert(-2, "]]") end end File.open(ARGV[1], "w") do |file| file.puts sorted end
This is a Wikipedia user page. This is not an encyclopedia article or the talk page for an encyclopedia article. If you find this page on any site other than Wikipedia, you are viewing a mirror site. Be aware that the page may be outdated and that the user in whose space this page is located may have no personal affiliation with any site other than Wikipedia. The original page is located at https://en.wikipedia.org/wiki/User:Digitalme/alphabetize.rb. |