Sort by just Month name and day. Bash

∥☆過路亽.° 提交于 2020-07-07 12:40:28

问题


Hello Trying to sort this list by Month and day. Can not get it staight. Any pointers ?

List example:

Jul 23 Drive :NTFS (Windows 31.6 GB/29.4 GiB) Details : Mounted /dev/sdc1 (Read-Write, label "FreeAgent GoFlex Drive", NTFS 3.1)
Jul 30 Drive :NTFS (Windows 31.6 GB/29.4 GiB) Details : Mounted /dev/sdb1 (Read-Write, label "HP USB FD", NTFS 3.1)
Aug 2 Drive :NTFS (Windows 31.6 GB/29.4 GiB) Details : Mounted /dev/sdb1 (Read-Write, label "WINPART", NTFS 3.1)
Jul 24 Drive :EXT (Linux) Details : EXT3-fs (sdc1)
Jul 25 Drive :EXT (Linux) Details : EXT3-fs (sdb1)
Jul 27 Drive :EXT (Linux) Details : EXT4-fs (sdb2)
Aug 2 Drive :EXT (Linux) Details : EXT3-fs (sdb1)
Aug 2 Drive :EXT (Linux) Details : EXT4-fs (sdb1)

回答1:


If you version of sort supports it:

sort -k1,1M -k2,2n



回答2:


when working on foreign computers we must set the language before sorting this kind of data:

LC_ALL=C sort -k1,1M -k2,2n file.txt


来源:https://stackoverflow.com/questions/12162210/sort-by-just-month-name-and-day-bash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!