How do I sort lines alphabetically?

How do I sort lines alpfabetically?

The help on this page is mostly provided by users like you.

An important aspect is the correct specification of the tags.
Choose at least one of the valid tags that match your situation: Writer, Calc, Draw, Impress, Math, Base or Common.

Your question and its description should be as detailed as possible.
When writing your question and description, please keep in mind that no one can look over your shoulder.
Please, basically you have to specify the operating system and the LibreOffice version (three digits, e.g. 7.3.2).
Furthermore, specify the file type in which you saved.
Edit your initial question, to do it.
Thanks.
All important information about your initial question should be present in the initial question box, otherwise edit and complete it.
Do not use comments for this.
If you have already fulfilled some of these requirements, so much the better.


You may want to upload a reduced and anonymized file here so that someone can examine it.


Here you can find the further References for this page.


Thank you for your consideration.

2 Likes

For Writer: select the lines, then Tools > Sort.

EDIT Make sure that the lines are really paragraphs, because the sort command will only sort by paragraph, not by line in a paragraph.

By the way, it really helps if you explain yourself more fully.

1 Like

should we mention that lines here are actually paragraphs?

2 Likes

@karolus: you’re right.

It does not sort, still looks like this.
What should I explain?

Germany
Norway
Sweden
Finland
China
Vietnam
USA
Denmark
Estonia
Latvia
Lithuania
France
Scotland
England
Wales
Nothern Ireland
Portugal
Morocco
Spain
Egypt
Austria
Belgium
Holland
Switzerland
Italy
Bosnia and Herzegovina
Croatia
Slovenia
Montenegro
Kosovo
Bulgaria
Romania
Poland
Russia
Turkey

Thanks, and I repeat: What should I explain?

Have you selected your list before applying Sort?
If you didn’t, Writer, supposing your question is relative to Writer and not to Calc or Impress (you didn’t change tag common), will sort the paragraph containing the cursor. Sorting a single paragraph is a no-op.

Hit Ctrl+F10 to show the non-printable characters. Your lines might be separated by line feeds (symbol: back arow). This means that all the words belong to one paragraph. The end of a paragraph is shown by a pilcrow: ¶.
Select the list.
Call menu:Edit>Find&Replace…
Below “Other options” check “Regular expressions”
Find: \n
Replace: \n
(yes, Find and Replace are the same, don’t ask yet)
Hit [Replace All] and every line should be terminated by a ¶.
Then call Tools>Sort…

Thanks, but line numbering is easier :slight_smile:

If you copy a list from HTML, such as the list in your earlier comment, the items are often separated by line feeds, not paragraphs, so the list cannot be sorted until the line feeds are replaced by paragraphs. The Find and Replace is to find the line feeds and replace them with paragraphs, see \n in List of Regular Expressions

Your image shows paragraph marks between entries so you do not need to do Find and Replace for that particular list. So just:

  • Select your entire list and click Tools > Sort
  • Enter your sort requirements there (the default setting is probably what you want) and click OK.

The sort procedure has been given twice already in this question. What result do you get when you do that?

And how do line numbers sort the country names?

1 Like