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
More Posts related to Bash,
- How to use Autocomplete and Autosuggestion in Shell Commands
- Bash How to Save Output of a Command to a Variable
- How to know the current shell you are logged in?
- How to Echo Bash Command to a File
- Bash Command to Get Absolute Path for a File
- How to Split a String based on Delimiter in Bash Scripting
- Bash: Command Line Arguments to Bash Script Examples
- Bash Command to Download a File From URL
- How to check if a Command Exists using Bash Script
- Ways to Increment a counter variable in Bash Script
- Know Bash shell version command
- Bash command to Read, Output and Manipulate JSON File
- Bash Command to Base64 Decode a String
- Bash Command to Check Python Version
- Bash: Command to Find the Length of a String
- What is $$ in Bash Shell Script- Special Variable
- Bash - How to check if a Command Failed?
- List all Username and User ID using Bash Command
- Command to Sort File In Reverse Order [Unix/Linux/macOS]
- bash: netstat: command not found
- Bash Command To Go Back To Previous Directory
- [Fix] bash: script.sh: /bin/bash^M: bad interpreter: No such file or directory
- How to check your IP using bash for Windows?
- Bash Command To Check If File Exists
- Convert String from uppercase to lowercase in Bash
More Posts:
- Permanently set $PATH variable in Mac Zsh shell - MacOS
- How to enable more encoding support in Mac Terminal - MacOS
- M1/M2 Mac VirtualBox Unsupported hardware architecture detected! - MacOS
- Save current timestamp in MySQL using PHP mysqi binding - PHP
- Android Studio 1.3 beta now Available for Developers - Android-Studio
- How to See Hidden Folders and Files on macOS - Mac-OS-X
- SharePoint update append Required Field to display name of mandatory columns - SharePoint
- Parsing a YAML file in Python Example - Python