Sorting text in DOS — reversing alphabetical order: Which DOS command line correctly sorts the contents of a file in reverse order and sends the result to the screen (or can be redirected)?
-
ASORT > filename
-
BSORT < filename
-
CSORT /R < filename
-
DSORT /V < filename
-
ENone of the above
Answer
Correct Answer: SORT /R < filename
Explanation
Introduction / Context:The DOS SORT filter reads from standard input and writes sorted text to standard output. Mastering its switches lets you quickly reorder data without external tools. Reversing the sort requires a specific flag.
Given Data / Assumptions:
- The input is a text file, referenced via standard input redirection.
- We want reverse (descending) sort order.
- We are using the native DOS SORT options.
Concept / Approach:
By default, SORT sorts ascending. The /R switch reverses the sort order. DOS typically uses redirection (<) to feed a file into SORT. Therefore, the correct pattern is SORT /R < filename. You can also redirect output to a new file with > out.txt if needed.
Step-by-Step Solution:
Choose SORT as the filter tool.Apply reverse order switch: /R.Use input redirection: < filename.Optionally redirect output to a file with > newfile.Verification / Alternative check:
Typing SORT /? in DOS lists switches; /R is documented as reverse sort order. Test with a small file to observe reversed output.
Why Other Options Are Wrong:
- SORT > filename: attempts to write SORT's output but provides no input; it does not reverse order.
- SORT < filename: correct for ascending, but not reverse.
- SORT /V: not a standard reverse-order switch in DOS SORT.
- None of the above: incorrect because a correct solution exists.
Common Pitfalls:
Forgetting redirection, assuming SORT takes the filename as a direct argument in all DOS versions; omitting /R and wondering why the order is ascending.
Final Answer:
SORT /R < filename