
To sort a file in reverse order make use of the command sort.
Sort File in Rever Alphabetical Order:
Let's take a text file that has unsorted contents as shown below,
myUnsortedFile.txtAmerica
Brazil
Japan
China
India
Russia
Ukraine
France
Germany
To sort this file in revere order make use of the sort command with -r option for reverse,
# sort -r myUnsortedFile.txt
Ukraine
Russia
Japan
India
Germany
France
China
Brazil
America
What is the file has lines that contain special characters and numbers,
cat myFile.txt
America
1
Brazil
#
Japan
@
China
India
!
Russia
Ukraine
2
France
Germany
After Reverse Sorting:
# sort -r myFile.txt
Ukraine
Russia
Japan
India
Germany
France
China
Brazil
America
@
2
1
#
!
Sort File in Rever Numeric Order:
File:1 America
2 Brazil
3 Japan
4 China
5 India
6 Russia
7 Ukraine
8 France
9 Germany
Make use of -n and -r options together to sort the contents of the file in reverse numeric order,
# sort -nr myFile.txt
9 Germany
8 France
7 Ukraine
6 Russia
5 India
4 China
3 Japan
2 Brazil
1 America
- How to Assign Bash Command to Variable
- How to Kill a port using bash terminal command?
- Bash For Loop Example
- bash: netstat: command not found
- Bash getopts Command Example
- How to fix bash ping command not found error
- [Fix] bash: script.sh: /bin/bash^M: bad interpreter: No such file or directory
- [fix] bash: ssh: command not found
- Fix bash: script.sh: Permission denied Error
- bash: ls command to see list files in current directory all subdirectories
- How to see Created Accessed Modified and Changed dates of a file using bash terminal command
- How to use Autocomplete and Autosuggestion in Shell Commands
- Bash Hello World! Script Tutorial
- Install Bash Completion on macOS
- bash get year 2021 calendar
- How to create new user account in Windows bash
- Bash command to wait for seconds
- Know Bash shell version command
- How to start or open a new bourne-again shell (bash) session on Windows using Command Line CMD
- How to check your IP using bash for Windows?
- Bash Script to prefix files with sequential numbers in a directory
- How to Compare Strings in Bash
- Command to Sort File In Reverse Order [Unix/Linux/macOS]
- How to know the current shell you are logged in?
- List all Username and User ID using Bash Command
- Add two numbers using Java Generics - Java
- How to Setup maven on Mac (macOS) - Mac-OS-X
- Fix - Microsoft Windows Error Code: 0xA00F4244 NoCamerasAreAttached - Microsoft
- 25 Notepad++ Command Argument List - NotepadPlusPlus
- Java Spring Boot 3 Web Hello World with Gradle in IntelliJ - Java
- How to change Android EditText Cursor Color - Android
- Add Current Date and Time in Notepad++ - NotepadPlusPlus
- Ubuntu zsh: command not found: nano - zsh