Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用bash对逗号分隔的文件进行排序_Bash_Sorting - Fatal编程技术网

使用bash对逗号分隔的文件进行排序

使用bash对逗号分隔的文件进行排序,bash,sorting,Bash,Sorting,我有以下资料: http://www.google.com/site,11/30/2012 6:51:30 PM http://www.google.com/site,10/1/2012 6:51:30 PM http://www.google.com/site,11/16/2012 6:51:30 PM http://www.google.com/site,8/1/2012 6:51:30 PM 我要按MM/DD/YYYY排序 http://www.g

我有以下资料:

    http://www.google.com/site,11/30/2012 6:51:30 PM
    http://www.google.com/site,10/1/2012 6:51:30 PM
    http://www.google.com/site,11/16/2012 6:51:30 PM
    http://www.google.com/site,8/1/2012 6:51:30 PM
我要按MM/DD/YYYY排序

    http://www.google.com/site,8/1/2012 6:51:30 PM
    http://www.google.com/site,10/1/2012 6:51:30 PM
    http://www.google.com/site,11/16/2012 6:51:30 PM
    http://www.google.com/site,11/30/2012 6:51:30 PM
我可以使用sort命令、uniq命令、tr、sed等。我没有访问awk的权限。有什么想法吗<代码>排序-t“,”-k1工作排序。

尝试执行以下操作:

sort -n -t "," -k 2 file.txt

读行时
;做
s=$(日期-d“${line#*,}”+%s)
回音$s$行
完成

因此,对于从日期字符串(位于逗号之后)创建自历元起秒数的每一行,将其用作排序键,并将其从结果输出中删除。

我使用sort命令做了一些工作,发现了我的问题,这似乎起到了作用:

    cat s.txt | sort -n -t"/" -k 4,4n -k 5,5n
    https://www.virustotal.com/,9/16/2012 8:19:00 AM
    https://www.virustotal.com/,10/6/2012 9:20:59 AM
    https://www.virustotal.com/,11/1/2012 9:20:22 AM
    https://www.virustotal.com/,11/4/2012 9:11:02 AM
    https://www.virustotal.com/,11/6/2012 8:50:27 AM
    https://www.virustotal.com/,11/12/2012 6:51:32 PM
反向:

    cat s.txt | sort -n -t"/" -k 4,4nr -k 5,5nr
    https://www.virustotal.com/,11/12/2012 6:51:32 PM
    https://www.virustotal.com/,11/6/2012 8:50:27 AM
    https://www.virustotal.com/,11/4/2012 9:11:02 AM
    https://www.virustotal.com/,11/1/2012 9:20:22 AM
    https://www.virustotal.com/,10/6/2012 9:20:59 AM
    https://www.virustotal.com/,9/16/2012 8:19:00 AM

但是,我需要在逗号后这样做,因为带有更多“/”的站点不会像
http://site.com/go/to/somelink,2012年9月16日上午8:19:00

这不一定有效:例如,尝试使用
11/16/2012
11/3/2012
作为日期。是否有一种方法可以通过单个排序命令来执行此操作?我觉得我很接近了。我不确定你能不能告诉“排序”先检查年份,然后是月份,然后是月份的哪一天。
    cat s.txt | sort -n -t"/" -k 4,4n -k 5,5n
    https://www.virustotal.com/,9/16/2012 8:19:00 AM
    https://www.virustotal.com/,10/6/2012 9:20:59 AM
    https://www.virustotal.com/,11/1/2012 9:20:22 AM
    https://www.virustotal.com/,11/4/2012 9:11:02 AM
    https://www.virustotal.com/,11/6/2012 8:50:27 AM
    https://www.virustotal.com/,11/12/2012 6:51:32 PM
    cat s.txt | sort -n -t"/" -k 4,4nr -k 5,5nr
    https://www.virustotal.com/,11/12/2012 6:51:32 PM
    https://www.virustotal.com/,11/6/2012 8:50:27 AM
    https://www.virustotal.com/,11/4/2012 9:11:02 AM
    https://www.virustotal.com/,11/1/2012 9:20:22 AM
    https://www.virustotal.com/,10/6/2012 9:20:59 AM
    https://www.virustotal.com/,9/16/2012 8:19:00 AM