Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Merkava_4

macrumors 6502a
Original poster
Hi all.

Is there a way to alphabetize a list in TextEdit? All I have is a list of street addresses.

I would rather sort by street name alphabetically instead of by street number. Thank You!
 
The functionality does not exist in that app by default.
You can run "cat filename | sort" in a terminal window for a sorted output.
 
Hi all.

Is there a way to alphabetize a list in TextEdit? All I have is a list of street addresses.

I would rather sort by street name alphabetically instead of by street number. Thank You!
If you wanted to use Numbers as an intermediary helper app (preinstalled in every modern Mac), you could select and copy the text in TextEdit, paste it into Numbers, sort it there, copy it back to the clipboard and then Paste and Match Style in TextEdit. Only takes a minute, if you know the steps.
 
  • Like
Reactions: conmee
If you wanted to use Numbers as an intermediary helper app (preinstalled in every modern Mac), you could select and copy the text in TextEdit, paste it into Numbers, sort it there, copy it back to the clipboard and then Paste and Match Style in TextEdit. Only takes a minute, if you know the steps.
Thank you for helping. After I open Numbers and click New Document, it wants me to select a template. I need a blank page like what's in TextEdit but I don't see one. I just have a list of addresses that need to be sorted alphabetically by street name.
 
After I open Numbers and click New Document, it wants me to select a template. I need a blank page like what's in TextEdit but I don't see one. I just have a list of addresses that need to be sorted alphabetically by street name.
You should be able to scroll down the list of templates in Numbers and find the Basic - Blank template. Just use that one. Don't worry about the gridlines—they will not copy over to TextEdit, if you use "Paste and Match Style" when you paste your data from Numbers to Excel.

The bigger problem with automatic sorting is that it will sort on the first characters it finds on each line.

For example, if your text reads: "123 S. Main St.", it will sort on "123", not on "Main St." If you want to sort on the street name ("Main St."), you will need to take a different approach.

To properly sort, the computer needs to know what the street names are and what the text format is. Each address also has to follow that specific format. If your addresses contain mixed formats (such as if your address book contains people from different countries), it will not work.

Also, if the names are mixed in with the addresses, Numbers (or any app, for that matter) will not magically find the street addresses and sort the records for you. It will sort everything.

As an example, let's say you have this list of addresses in TextEdit:

123 N. Main St.
456 S. Birch Ave.
14935 W. Lotus Way

If you copy and paste into Numbers as-is, you will get this:

Numbers_example_1.png


Not too great, right? You can adjust the import settings in Numbers to "delimited" to make it look more like this:
Numbers_example_2.png

...which is more like what you want.
However, you still have to tell Numbers which item to sort on, and Numbers has to figure out what you mean.

How many addresses are we talking about?
It might be easier if you created a new address book in Numbers with the proper name and address columns. Then you could sort much more easily. If you have a lot of addresses all in different formats, though, it's a lot of work.
 
If you own Microsoft Excel it you can use the text import wizard and sort from there
True, but the point of this thread was that the OP is going to have a hard time sorting on street names that are imported from a TextEdit file. Excel is probably not going to fare any better than Numbers in that regard, plus Excel is not preinstalled on Macs to begin with, so that’s another hurdle for the OP to cross.

It’s easy enough to sort on text, but it has to be in a uniform format. AFAIK, spreadsheets won’t magically detect street names and sort on them—the user has to specify the street name “fields”, and that data has to be in a standardized format so that all data records are treated in the same way.

Bottom line: the OP probably has to redo their data in a spreadsheet format in order to actually sort on street names, which was the OP’s original request.
 
  • Like
Reactions: NoBoMac
^this.

Can manipulate it a bit to start, if fairly consistent. For example:

Code:
% cat foo
123 Main St
543 Yahoo Cir
678 Birch Ave
100 Elm Dr
%
cat foo | sed "s/ /\t/" | sort -k2
678    Birch Ave
100    Elm Dr
123    Main St
543    Yahoo Cir
%

Or just skip the sort chunk (just do: cat foo | sed "s/ /\t/" > foo2) and import in a spreadsheet app.

(now, if not a "clean" format re number of spaces after the street number, will get some unexpected results; or: some street names have directions others not; but all a starting point/option)

Shortcuts has some parsing capabilities using regex patterns but no sorting iirc, so would need to create a new file and do a shell call to sort the new file.
 
  • Like
Reactions: jchap
Can manipulate it a bit to start, if fairly consistent. For example:

Code:
% cat foo
123 Main St
543 Yahoo Cir
678 Birch Ave
100 Elm Dr
%
cat foo | sed "s/ /\t/" | sort -k2
678    Birch Ave
100    Elm Dr
123    Main St
543    Yahoo Cir
%
I like the way you separated the numbers from the street names.

Indeed, it's a question of whether the original data has consistent street number/name formats to begin with. That would give you a good tab-delimited format that you could import into a spreadsheet and manipulate further.

It also sounds like the OP has names mixed in with the addresses, so then it would be necessary to parse the names out from the addresses.

I would probably use a tool like CotEditor to do a batch find/replace with regex—lots of trial and error. Either way, this kind of task assumes that (1) the original data has a standardized format, and (2) the OP knows how to use regex with Terminal or some kind of tool, or is willing to just redo the data in a spreadsheet app.
 
  • Like
Reactions: NoBoMac
How many addresses are we talking about?
159 addresses. I went ahead and alphabetized them manually by dragging them up and down the page.

It took me about an hour. One example is Ezie Ave, 3514 N instead of 3514 N Ezie Ave.
 
  • Wow
Reactions: jchap
159 addresses. I went ahead and alphabetized them manually by dragging them up and down the page.

It took me about an hour. One example is Ezie Ave, 3514 N instead of 3514 N Ezie Ave.
It's good that you could get the data the way you wanted.

I would suggest putting it in spreadsheet format (Numbers, Excel, etc.) in the future, though. Much easier to sort and work with for the long term.
 
Or use tables in Notepad Notes: can drag the rows around. And can copy/paste to a spreadsheet to get rows and columns to swizzle there.
 
Last edited:
  • Like
Reactions: jchap
Or use tables in Notepad: can drag the rows around. And can copy/paste to a spreadsheet to get rows and columns to swizzle there.
You must mean Notes, as Notepad is a Windows app... 😆
That's nice, how you can click and drag to move the rows up and down in Notes. Swizzle!
Also interesting is how you can simply select text in Notes and then click the "Add a table" icon, and Notes will automatically convert the selected text into table rows. Microsoft Word can do that, but Pages does not seem to offer that option.
 
Last edited:
This is so easy in LibreOffice (or any other document editor): select text, convert text to table, sort table by whatever column you want, convert table to text.
 
You can use Pages.

  • Paste your list in Pages.
  • Highlight your text.
  • Use the Writing Tools Panel. Use instructions similar to this: Put this text in a table. Use a separate column for the street number, street name, city and state.
  • Once you are in a table you can sort by any column
 
I'd strongly recommend using BBEdit for any kind of text manipulation. Sort, replace, insert, process -- it's been THE text editor for Mac since Steve Jobs was a small beige box.
 
  • Like
Reactions: NoBoMac
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.