Situatie
SORT command is used to sort a file, arranging the records in a particular order. By default, the sort command sorts file assuming the contents are ASCII. Using options in the sort command can also be used to sort numerically.
Solutie
Pasi de urmat
Let’s start with a simple example. Consider a file named ‘file.txt’ with the following content:
cat file.txt
Here we used cat command to display the content inside the file name ‘file.txt’.
To sort the lines alphabetically, you can use the following command:
sort file.txt
This command does not actually change the input file, i.e. file.txt . We can verify this using cat command .
How to Sort Lines in Text Files with Uppercase and Lowercase Using sort Command
Sort function with mix file i.e. uppercase and lower case: When we have a mix file with both uppercase and lowercase letters then first the upper case letters would be sorted following with the lower case letters.
Example: If we have a text file which has both Uppercase andlowercase characters.
cat mix.txt
Here we used cat command to display the content inside the file name ‘mix.txt’.
To sort the lines alphabetically which contain uppercase and lowercase letters, you can use the following command:
sort mix.txt
Leave A Comment?