Windows terminal: the sort function

The tutor shares a great find on the Windows terminal.

When I was a kid, we spent many hours, in grades three through six, rewriting lists of words in alphabetical order. The advantage was twofold: writing practice (which, back then, was practically half of elementary school) and understanding how words are ordered in a dictionary. Those exercises could be ponderous; here I am, anyway:)

Today, you needn’t alphabetize a list yourself. Just type it, one word per line, to a file, then let the Windows terminal sort function take care of it. The basic syntax, at the command prompt, is

sort input_file /o output_file

To test the sort command, I first created a file called tosort0.txt. Its contents:

lewis
louise
tender
ant
importation
22
101
01
a
!

At the command prompt, I then ran

sort tosort0.txt /o sorted0.txt

Next, I opened the file sorted0.txt, which hadn’t existed before. Indeed, its contents are

!
01
101
22
a
ant
importation
lewis
louise
tender

However, the file tosort0.txt remains unchanged.

Next I ran, from the command line,

sort tosort0.txt

The list, in alphabetical order, printed to the screen.

Once again: if you don’t specify the output file, you’ll see the sorted list print right to the command line. If you specify an output file that doesn’t exist, the command will create it, then print the sorted list to it. The input file whose contents get sorted remains unchanged.

Neat, huh?

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Tagged with: , , ,

Leave a Reply