Pages

Thursday, June 29, 2017

7 Interesting Linux ‘sort’ Command Examples – Part 2

In our last article we have covered various examples on sort command, if you’ve missed, you can go through it using below link. In continuation to the last post this post aims at covering remaining of sort command so that both the article together serves as complete guide to Linux ‘sort‘ command.
  1. 14 ‘sort’ Command Examples in Linux
Before we continue further, create a text file ‘month.txt‘ and populate it with the data as given below.

$ echo -e "mar\ndec\noct\nsep\nfeb\naug" > month.txt
$ cat month.txt
Populate Content
15. Sort the file ‘month.txt‘ on the basis of month order by using switch ‘M‘ (–month-sort).
$ sort -M month.txt
Important: Note that ‘sort‘ command needs at least 3 characters to consider month name.
Sort File Content by Month in Linux

16.
 Sort the data that is in human readable format say 1K, 2M, 3G, 2T, where K,M,G,T represents Kilo, Mega, Giga, Tera.
$ ls -l /home/$USER | sort -h -k5
Sort Content Human Readable Format
17. In the last article we have created a file ‘sorted.txt‘ in example number 4 and another text file ‘lsl.txt‘ in example number 6. We know ‘sorted.txt‘ is already sorted while ‘lsl.txt‘ is not. Lets check both the files are sorted or not using sort command.
      ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
                                                    ► Read more: http://adf.ly/1nBXz9
      ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

No comments:

Post a Comment