-3

I am using "sort table" bookmarklet that works very well.

https://www.squarefree.com/bookmarklets/pagedata.html

I can use it on any page where there is a table. For e.g.

https://mr.wikipedia.org/wiki/%E0%A4%B5%E0%A4%BF%E0%A4%95%E0%A4%BF%E0%A4%AA%E0%A5%80%E0%A4%A1%E0%A4%BF%E0%A4%AF%E0%A4%BE:%E0%A4%B6%E0%A5%81%E0%A4%A6%E0%A5%8D%E0%A4%A7%E0%A4%B2%E0%A5%87%E0%A4%96%E0%A4%A8_%E0%A4%9A%E0%A4%BF%E0%A4%95%E0%A4%BF%E0%A4%A4%E0%A5%8D%E0%A4%B8%E0%A4%BE_%E0%A4%B8%E0%A5%81%E0%A4%A7%E0%A4%BE%E0%A4%B0%E0%A4%A3%E0%A4%BE_%E0%A4%AA%E0%A5%8D%E0%A4%B0%E0%A4%95%E0%A4%B2%E0%A5%8D%E0%A4%AA

But is it possible to sort the text in the next section that does not have table properties? For e.g. how do I sort the words in the section?

===इंग्लिश शब्दास मराठी शब्द सूचना===

Is it possible to re-write the same bookmarklet to sort text in any input textbox?


Update:

I am using decorate-sort-undecorate idiom

awk '/=/ {c++} {print c+1, $0}' file.txt | sort -n | cut -d' ' -f2- | sed '/^$/d'

It will look for "equal to" sign and number all the lines in that particular section to be later sorted on. This is working as expected. But I need to copy-paste the text from wiki to linux prompt. I guess bookmarklet will be quicker. The page mentioned above is just an example. I need to be able to sort the text typed in any text area of the browser. The relevant wiki page does not mention how to do this in javascript.

https://en.wikipedia.org/wiki/Schwartzian_transform

shantanuo
  • 31,689
  • 78
  • 245
  • 403
  • 9
    most of the people in here don't even recognise that as a text, maybe try some English example? and what did you try? it's against the rules of SO to ask about a ready-to-use solution – Flash Thunder Feb 27 '21 at 10:21
  • The use of the Schwartzian transform is (no offense, and unless I am misunderstanding) inappropriate and non-sensical. – ninjagecko Mar 05 '21 at 22:01
  • I learned that term from a similar question :) @ninjagecko https://stackoverflow.com/questions/66345194/sort-words-per-section – shantanuo Mar 07 '21 at 03:48
  • This is the bookmarklet that will sort unique words in browser text area: https://gist.github.com/shantanuo/1fdaad6a29b0ffb08f72827daca13fbc – shantanuo May 15 '21 at 15:01

1 Answers1

1

Indeed you are on the right track with copy-pasting the text; the bookmarklet depends on a table "input format", so you have to either make the bookmarklet understand a "list in prose-form input format" (and give it a way to output back to you), or copy-paste the list and use some other tool.

A bookmarklet which will sort a list of words is quite doable, but not very useful in general, so I will just point out the better solution of copy-pasting the text into another programming language:

You will need to:

  1. import the data into your favorite programming language
  2. parse the data into a List type
  3. sort the List
  4. output the result

You can do this in the browser in the developer console with javascript as follows:

type:

var myList = `very long list of words`.split(' ');  //replace ' ' with ', ' perhaps if there are commas

result: ["very", "long", "list", "of", "words"]

Alternatively this might work better in languages without commas:

var myList = `very long list of words`.match(/\S+/g);  // match contiguous sequence of non-spaces

Then sort:

myList.sort( (a,b) => a.localeCompare(b, 'mr', {ignorePunctuation: true}));

Then you can either examine the output as-is, print with console.log( myList.join(', ') ) or .join('\n'), use console.table (or do something else to let you copy-paste as a table into e.g. a spreadsheet), etc.

You might also consider Python or another programming language. There is no reason to care about efficiency (per the link you wrote) unless you are a developer making this as some sort of tool, in which case you would need to clarify your use case to be more appropriate as a question. Even then, any notion of efficiency in a sorting algorithm is nonsense because they're all O(n log(n)). The entire idea of that Schwartzian transform is when you are sorting a list of large objects according to a key, and the computation of that key takes a long time. A string is not a large datatype. Bringing that up is like saying you need to go buy a jug of milk and thus must pre-perform integral calculations on the terrain topography to optimize the fuel efficiency of the car.

ninjagecko
  • 88,546
  • 24
  • 137
  • 145