一样工作
我有以下内容:
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等。我无法访问尴尬。有任何想法吗 ?sort -t "," -k1
有点工作。
while read line; do
s=$(date -d "${line#*,}" +%s)
echo $s $line
done < input.txt | sort -n | cut -d ' ' -f2-
因此,对于每行创建秒以来,从日期字符串开始(逗号之后),将其用作排序键,然后将其从结果输出中删除。
尝试这样做:
sort -n -t "," -k 2 file.txt
见
man sort
我对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,9/16/2012 8:19:00 AM