The file makes a great candidate for use with the
command because it is a text file with a separate piece of information on each line.
Each line contains three itemsseparated by commas. These items are interpreted as columns of information. The locations of the columns are identified with a number, starting with
for the first column (color),
for the second column (description), and
for the third column (quantity).
If I wanted to sort my clothes file by column, I would use the following command:
$ sort –t, +1 clothes
When forming a
command, you should include the
option which specifies the character used to separate columns in the file.
option must be followed by a separation character, such as the comma used in the above command.
You must also indicate the column number and file name you want the
command to act upon.
Just using the
command does not permanently change the file you are sorting. It only shows what the file would look like if it were sorted using various options.
If you want to change your file, use the
option with the
The following command changes the contents of the clothes file so that it is sorted by color, column +0.
$ sort –t, +0 –o clothes clothes
option tells the
command to store your output in a file, in this case clothes.
This file can have the same name as your original file, which results in a new version of the original. If you use a different file name, then your new file will contain the sorted information and your original file will contain the unsorted information.