Sort list in order by numeric suffix
Sort list in order by numeric suffix
Hi,
There must be an easy way to sort data numerically in Writer, but I cant seem to figure it out? By default my list is,
Name 1
Name 10
Name 100
Name 1000
Name 1001
Name 1002
Name 1003
etc etc
What I need is,
Name 1
Name 2
Name 3
Name 4
etc etc
Could someone tell me how to do this please?
Thanks
There must be an easy way to sort data numerically in Writer, but I cant seem to figure it out? By default my list is,
Name 1
Name 10
Name 100
Name 1000
Name 1001
Name 1002
Name 1003
etc etc
What I need is,
Name 1
Name 2
Name 3
Name 4
etc etc
Could someone tell me how to do this please?
Thanks
OpenOffice 4.1.12
Re: Sort list in numerical order?
try to create a helper column with numbers converted from the texts.
Then sort the data based on the converted numbers.
example:
https://forum.openoffice.org/en/forum/v ... hp?t=53379
Then sort the data based on the converted numbers.
example:
https://forum.openoffice.org/en/forum/v ... hp?t=53379
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Sort list in numerical order?
Are you trying to repace 10 with a 2 in the second name and the 100 with a 3 in the third name etc.?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Sort list in numerical order?
If the list is in a table with the names in one column and the numbers in another column, select the table then use Tools > Sort to sort the table using the numbers column as the sort key. If the list is not in a table, it must be converted to a table before it can be sorted.
If you need detailed instructions, upload a sample file.
After a closer look, the list doesn't have to be converted to a table, but there needs to be a separator character between the names and the numbers. A tab is usually used for the separator character.
If you need detailed instructions, upload a sample file.
After a closer look, the list doesn't have to be converted to a table, but there needs to be a separator character between the names and the numbers. A tab is usually used for the separator character.
AOO 4.1.14 on Ubuntu MATE 22.04
Re: Sort list in numerical order?
Ifs confusing for me because the first list is already in sort order. A tab can be added in front of the numbers with the following search and replace terms in the find/replace dialog and regular expressions ticked
\d*
\t&
(Explanation:
\d means any digit, * means any number of the preceding character
\t means a tab, & means include what was there originally)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
- Hagar Delest
- Moderator
- Posts: 32666
- Joined: Sun Oct 07, 2007 9:07 pm
- Location: France
Re: Sort list in numerical order?
Here is what worked for me, with a space in the Character field (in LibreOffice):
Name 1
Name 2
Name 10
Name 23
Name 100
Name 1000
Alphanumeric order gives Name 1000 before Name 2 since the first different character is taken into account (1).
Thus, you have to specify that you need a numeric order.
Please add [Solved] at the beginning of the title in your first post (top of the topic) with the 🖉 button if your issue has been fixed.
that gives (for example):Name 1
Name 2
Name 10
Name 23
Name 100
Name 1000
Alphanumeric order gives Name 1000 before Name 2 since the first different character is taken into account (1).
Thus, you have to specify that you need a numeric order.
Please add [Solved] at the beginning of the title in your first post (top of the topic) with the 🖉 button if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Re: Sort list in numerical order?
Using space as the Separator works on the example list, but I doubt that the real list just has "Name" on every line in the list. If there are real names like "John Smith" instead of just "Name", then there will be spaces in the names and a different character would have to be used for the Separator. A sample document with a real list is needed.
AOO 4.1.14 on Ubuntu MATE 22.04
- Hagar Delest
- Moderator
- Posts: 32666
- Joined: Sun Oct 07, 2007 9:07 pm
- Location: France
Re: Sort list in numerical order?
Indeed. But the idea is there. If there is an issue with its implementation sainty88, feel free to post again with a sample file as suggested by Bill.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Re: Sort list in numerical order?
Simple approch to »natural-sort« selected paragraphs :
run natural_sort_paras after selecting the Paras to sort.
for organizing your python-stuff use: apso.oxt from here
Code: Select all
import re
num_rex = re.compile(r"(\D+|\d+)")
def number_keys( para ):
match = num_rex.findall(para)
return [
int(group) if group.isdigit()
else group for group in match
]
def natural_sort_paras(*_):
doc = XSCRIPTCONTEXT.getDocument()
paras = doc.CurrentSelection[0]
paras.String = '\r'.join(sorted(paras.String.split('\n'),
key=number_keys))
for organizing your python-stuff use: apso.oxt from here
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Re: Sort list in numerical order?
It looks like formatting would be lost if there is any. From the OP's other thread, they have 5000 items, so might that run into the string size limit?
Another option might be to cut and paste or "paste special" into calc and sort it there and paste back.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Sort list in numerical order?
Assuming each paragraph has less than 100 chararcters, it should not a problem for python.
If each paragraph consists on 64kbit it would be a problem… but does it make sense to sort 5000 paragraphs each with 64kb ???
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)