我有一个带有数据的CSV
$cat content.csv
MD5 : 1d4571a01abfbfe1a653a86109c5587f , Detection : Unknown.Trojan.Generickd , Level : 5, Factor : 5, VT Positives 13
MD5 : 03f44b4a8eb4a3b88d8307452eb5b556 , Detection : Document-Word.Exploit.CVE-2012-0013 , Level : 5, Factor : 5, VT Positives 0
MD5 : 58e9db1ec0fa687ee7c1510504a087c8 , Detection : Document-Powerpoint.Trojan.Vba agent , Level : 5, Factor : 5, VT Positives 4
MD5 : 1d025e72e82199d1524a9249073b338d , Detection : Document-Powerpoint.Trojan.Valyria , Level : 5, Factor : 5, VT Positives 1
MD5 : b3039d8f5d616c77297f0da3d5b444ea , Detection : Win32.Trojan.Dynamer , Level : 5, Factor : 5, VT Positives 36
MD5 : 833ab86e5f3d915dba7eea7e79a9c11e , Detection : Win32.Virus.Sality , Level : 5, Factor : 5, VT Positives 42
MD5 : 4f08e1c23ba22eb3bb1e7a7f2418f187 , Detection : Document-Powerpoint.Trojan.Valyria , Level : 5, Factor : 5, VT Positives 1
MD5 : bed56264438a7da43a98073497c74f73 , Detection : DOS.Virus.Arcv , Level : 5, Factor : 5, VT Positives 31我想在第五个字段上做数值sort ( VT阳性),基于分隔符",",再加上所有字段(1到5)。
我试过了
$ cut -d"," -f 1,2,3,4,5 kiran | sort -k 5
MD5 : bed56264438a7da43a98073497c74f73 , Detection : DOS.Virus.Arcv , Level : 5, Factor : 5, VT Positives 31
MD5 : 1d025e72e82199d1524a9249073b338d , Detection : Document-Powerpoint.Trojan.Valyria , Level : 5, Factor : 5, VT Positives 1
MD5 : 4f08e1c23ba22eb3bb1e7a7f2418f187 , Detection : Document-Powerpoint.Trojan.Valyria , Level : 5, Factor : 5, VT Positives 1
MD5 : 58e9db1ec0fa687ee7c1510504a087c8 , Detection : Document-Powerpoint.Trojan.Vba agent , Level : 5, Factor : 5, VT Positives 4
MD5 : 03f44b4a8eb4a3b88d8307452eb5b556 , Detection : Document-Word.Exploit.CVE-2012-0013 , Level : 5, Factor : 5, VT Positives 0
MD5 : 1d4571a01abfbfe1a653a86109c5587f , Detection : Unknown.Trojan.Generickd , Level : 5, Factor : 5, VT Positives 13
MD5 : b3039d8f5d616c77297f0da3d5b444ea , Detection : Win32.Trojan.Dynamer , Level : 5, Factor : 5, VT Positives 36
MD5 : 833ab86e5f3d915dba7eea7e79a9c11e , Detection : Win32.Virus.Sality , Level : 5, Factor : 5, VT Positives 42
sort -t$"," -k 5 -n kiran
MD5 : 03f44b4a8eb4a3b88d8307452eb5b556 , Detection : Document-Word.Exploit.CVE-2012-0013 , Level : 5, Factor : 5, VT Positives 0
MD5 : 1d025e72e82199d1524a9249073b338d , Detection : Document-Powerpoint.Trojan.Valyria , Level : 5, Factor : 5, VT Positives 1
MD5 : 1d4571a01abfbfe1a653a86109c5587f , Detection : Unknown.Trojan.Generickd , Level : 5, Factor : 5, VT Positives 13
MD5 : 4f08e1c23ba22eb3bb1e7a7f2418f187 , Detection : Document-Powerpoint.Trojan.Valyria , Level : 5, Factor : 5, VT Positives 1
MD5 : 58e9db1ec0fa687ee7c1510504a087c8 , Detection : Document-Powerpoint.Trojan.Vba agent , Level : 5, Factor : 5, VT Positives 4
MD5 : 833ab86e5f3d915dba7eea7e79a9c11e , Detection : Win32.Virus.Sality , Level : 5, Factor : 5, VT Positives 42
MD5 : b3039d8f5d616c77297f0da3d5b444ea , Detection : Win32.Trojan.Dynamer , Level : 5, Factor : 5, VT Positives 36
MD5 : bed56264438a7da43a98073497c74f73 , Detection : DOS.Virus.Arcv , Level : 5, Factor : 5, VT Positives 31尝试了多个组合,它不像预期的那样工作。有什么建议吗?
发布于 2018-06-21 09:45:54
你可以用这个:
sort -t"," -k 5.15 -n file分隔符设置为逗号(在字符串之前不需要$ )。
执行数字排序的键是从第15个字符( VT Positives字符串的长度)开始的第5个字段。
正如sort手册页面中所说的那样:
KEYDEF是开始和停止位置的F.C[,F.C],其中F是字段号,C是字段中的字符位置。
发布于 2018-06-21 09:47:57
由于要排序的关键是整行的最后一部分,所以您可以在行前面复制它,对其进行排序,最后再删除它:
awk '{print $NF, $0}' kiran | sort -g | sed 's/^[0-9]\+//'发布于 2018-06-21 09:51:48
删除'VT阳性‘,排序,再放回去:
$ sed 's/, VT Positives / , /g' content.csv | sort -t, -n -k 5 | sed 's/\([0-9][0-9]*\)$/VT Positives \1/g'https://stackoverflow.com/questions/50965146
复制相似问题