Chinaunix

标题: 关于排序的问题,急! [打印本页]

作者: likerbupt    时间: 2012-10-08 15:50
标题: 关于排序的问题,急!
1)某格式日志中有若干行。每行中的分隔符是][,我现在要以每行的第9个字段进行排序,再输出完整的行。
2)接上面的问题,以每行的第9个字段进行排序,只输出互不相同的行。
作者: Shell_HAT    时间: 2012-10-08 16:00
能否给点数据以便测试?
作者: likerbupt    时间: 2012-10-08 16:41
回复 2# Shell_HAT



    [time=20120928021012][pd=map][os=iphone][ov=][sv=2.3.0.b][im=641a178e4e6debced83558fe7094ff11][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1347877263][lt=1][msid=254_0][0=42][1=9][2=17][3=18][4=21][5=3]
[time=20120928021013][pd=map][os=iphone][ov=][sv=4.0.0.b][im=39dfc147dda99c9c0a5276b4e688745a][sw=640][sh=920][ch=2415][mb=][ver=1][re=0][tm=1348624103][lt=1][msid=254_0][0=42][1=9][2=26][3=9][4=48][5=23]
[time=20120928021333][pd=map][os=iphone][ov=][sv=4.0.0.b][im=c860c8115c1bd20a01119bd8fa1a98652c9120c2][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=1348440602][lt=1][msid=254_0][0=42][1=9][2=24][3=6][4=50][5=2]
[time=20120928021032][pd=map][os=iphone][ov=][sv=1.5.0.b][im=27cad6269e7fd772ce29fe91a1451944c71583a0][sw=320][sh=480][ch=1099a][mb=][ver=1][re=0][tm=1213131099][lt=1][msid=254_1]
[time=20120928021051][pd=map][os=iphone][ov=][sv=1.5.0.b][im=57e2440d36c01a8110b63c12b2db8a9742875363][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=2998667055][lt=1][msid=254_1]
[time=20120928023102][pd=map][os=iphone][ov=][sv=1.2.0.b][im=2d708038836de8baeb35516cb153c1e319bd9c0b][sw=320][sh=480][ch=1099a][mb=][ver=1][re=0][tm=94121992][lt=1][msid=254_1]
[time=20120928021012][pd=map][os=iphone][ov=][sv=1.5.0.b][im=b4f928059a17e459436492787b30457a0ad8b631][sw=640][sh=960][ch=1415b][mb=][ver=1][re=0][tm=43943018][lt=1][msid=254_2][0=13320346][1=3830209][2=11][city=]
[time=20120928021020][pd=map][os=iphone][ov=][sv=4.0.0.b][im=ec45bb5dd4654d104d317e262b859e3dcaa3f7c6][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=1095734846][lt=1][msid=254_2][0=12966017][1=4824601][2=13][city=]
[time=20120928021229][pd=map][os=iphone][ov=][sv=1.5.0.b][im=c3b83ec44fe0a8ccb26fb7601c65732dd8238bb5][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=3806356201][lt=1][msid=254_2][0=12732617][1=3456361][2=13][city=]
[time=20120928033035][pd=map][os=iphone][ov=][sv=1.5.0.b][im=9bff552ca4ae2d43b63f6de2aecb4f06b5af346a][sw=640][sh=960][ch=1415b][mb=][ver=1][re=0][tm=825857282][lt=1][msid=254_3][0=4][1=3][2=151][3=87][city=]
[time=20120928033035][pd=map][os=iphone][ov=][sv=1.5.0.b][im=9bff552ca4ae2d43b63f6de2aecb4f06b5af346a][sw=640][sh=960][ch=1415b][mb=][ver=1][re=0][tm=837528832][lt=1][msid=254_3][0=5][1=0][2=173][3=235]
[time=20120928033332][pd=map][os=iphone][ov=][sv=1.0.0.b][im=30506df0dd1acd85bb2739573eb506524f3a0a75][sw=640][sh=960][ch=1113][mb=][ver=1][re=0][tm=2611089085][lt=1][msid=254_4][0=50][1=50][2=49][3=55][city=]
[time=20120928021012][pd=map][os=iphone][ov=][sv=2.3.0.b][im=641a178e4e6debced83558fe7094ff11][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1348304536][lt=1][msid=254_8][0=13423769][1=3219716][2=100][3=-1]
[time=20120928021017][pd=map][os=iphone][ov=][sv=4.0.0.b][im=a6101f8355ab6e5783861d89b8a8cf97][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1348675167][lt=1][msid=254_8][0=11674818][1=3052714][2=848][3=-1]
[time=20120928021946][pd=map][os=iphone][ov=][sv=3.0.0.b][im=2d9c5a675b221b4136ce8dac8c3c537f9f77f7ad][sw=640][sh=960][ch=1113][mb=][ver=1][re=0][tm=1348705062][lt=1][msid=254_8][0=12949666][1=4824652][2=998][3=-1]
[time=20120928021013][pd=map][os=iphone][ov=][sv=4.0.0.b][im=9f02f2d1cab351eb33427a6f9e1be8242d229c0b][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=1348674869][lt=1][msid=254_9]
[time=20120928021344][pd=map][os=iphone][ov=][sv=1.2.0.b][im=1c7a351dce4ddbc7588f89566d285d58433a6c81][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=37751434][lt=1][msid=254_9]
[time=20120928021102][pd=map][os=iphone][ov=][sv=4.0.0.b][im=829acb82da2afdb74976c9e6e206371d][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1348587797][lt=1][msid=254_10]
[time=20120928032550][pd=map][os=iphone][ov=][sv=1.2.0.b][im=d986d1dd009d82accb08c8ad724084e5fb9dd8a1][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=15821984][lt=1][msid=254_10]
[time=20120928021012][pd=map][os=iphone][ov=][sv=2.3.0.b][im=641a178e4e6debced83558fe7094ff11][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1347877263][lt=1][msid=254_11][0=iPhone4][1=1]
[time=20120928021013][pd=map][os=iphone][ov=][sv=4.0.0.b][im=39dfc147dda99c9c0a5276b4e688745a][sw=640][sh=920][ch=2415][mb=][ver=1][re=0][tm=1348624103][lt=1][msid=254_11][0=iPhone3][1=1]
[time=20120928021333][pd=map][os=iphone][ov=][sv=4.0.0.b][im=c860c8115c1bd20a01119bd8fa1a98652c9120c2][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=1348440602][lt=1][msid=254_11][0=iPhone3][1=3]
[time=20120928021012][pd=map][os=iphone][ov=][sv=2.3.0.b][im=641a178e4e6debced83558fe7094ff11][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1347877263][lt=1][msid=254_12][0=5.100000]
[time=20120928021013][pd=map][os=iphone][ov=][sv=4.0.0.b][im=39dfc147dda99c9c0a5276b4e688745a][sw=640][sh=920][ch=2415][mb=][ver=1][re=0][tm=1348624103][lt=1][msid=254_12][0=5.000000]
[time=20120928021333][pd=map][os=iphone][ov=][sv=4.0.0.b][im=c860c8115c1bd20a01119bd8fa1a98652c9120c2][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=1348440602][lt=1][msid=254_12][0=6.000000]
[time=20120928021012][pd=map][os=iphone][ov=][sv=2.3.0.b][im=641a178e4e6debced83558fe7094ff11][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1347877346][lt=1][msid=254_13]
[time=20120928021013][pd=map][os=iphone][ov=][sv=3.0.0.b][im=f5aa2195b4ea4bf837cba4b96c0cbf8f][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1348566734][lt=1][msid=254_13]
[time=20120928021417][pd=map][os=iphone][ov=][sv=4.0.0.b][im=a97943ea87e0b354b27e1c2489f942e7][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1348697763][lt=1][msid=254_13]
[time=20120928021012][pd=map][os=iphone][ov=][sv=2.3.0.b][im=641a178e4e6debced83558fe7094ff11][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1347877263][lt=1][msid=254_14]
[time=20120928021013][pd=map][os=iphone][ov=][sv=4.0.0.b][im=cec8d18504c3b2b1a07487ccda341020][sw=640][sh=920][ch=2415][mb=][ver=1][re=0][tm=1348675239][lt=1][msid=254_14]
[time=20120928021721][pd=map][os=iphone][ov=][sv=4.0.0.b][im=35ca5b9a1ddf1d56d702400237e472b1][sw=640][sh=920][ch=2415][mb=][ver=1][re=0][tm=1348698428][lt=1][msid=254_14]
[time=20120928021012][pd=map][os=iphone][ov=][sv=2.3.0.b][im=641a178e4e6debced83558fe7094ff11][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1347877346][lt=1][msid=254_15][0=0][1=0][2=11][3=195]
[time=20120928021013][pd=map][os=iphone][ov=][sv=3.0.0.b][im=f5aa2195b4ea4bf837cba4b96c0cbf8f][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1348567208][lt=1][msid=254_15][0=1][1=2][2=0][3=0]
[time=20120928021421][pd=map][os=iphone][ov=][sv=4.0.0.b][im=eb710ade31b1be988402eef2d7fcbdce][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1348392084][lt=1][msid=254_15][0=1][1=6][2=0][3=0]
[time=20120928021103][pd=map][os=iphone][ov=][sv=4.0.0.b][im=63e78dde88154bd9bdbd3b9728a6ac90][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1348675992][lt=1][msid=254_16]
[time=20120928031142][pd=map][os=iphone][ov=][sv=4.0.0.b][im=3db1732949ab0c7c4be62e4e970d0ac3e11ded57][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=1348464976][lt=1][msid=254_16]
[time=20120928021012][pd=map][os=iphone][ov=][sv=4.0.0.b][im=91bdd973fcb0fdc3b0e28b7f97f8a28e][sw=640][sh=920][ch=1099a][mb=][ver=1][re=0][tm=1348674957][lt=1][msid=254_17]
[time=20120928021024][pd=map][os=iphone][ov=][sv=4.0.0.b][im=d6fda3b9fac5c43979f1aee40de3b4e4a37e5118][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=1348675321][lt=1][msid=254_17]
[time=20120928024256][pd=map][os=iphone][ov=][sv=4.0.0.b][im=df5f4ee15160c31869a6e8371b860f90206cf3ee][sw=640][sh=960][ch=1099a][mb=][ver=1][re=0][tm=1348721756][lt=1][msid=254_17]

作者: apachewebser    时间: 2012-10-08 16:57
坐等         
作者: ljwd1000    时间: 2012-10-08 16:59
  1. awk -F'[][]' '{for(i=1;i<=NF;i++)if($i~/^ch/){a[$i]=$0}}END{len=asorti(a,b);for(i=1;i<=len;i++)print a[b[i]]}'  file
复制代码
试试,是不是要的结果?
作者: dn833    时间: 2012-10-08 17:32
  1. sort -t "[" -k10
复制代码
排序
  1. awk 'BEGIN{FS=OFS="["}!a[$10]++'
复制代码
去重

作者: yexingren23    时间: 2012-10-08 18:29
sort -t ']' -k 9  test.txt
作者: L_kernel    时间: 2012-10-10 21:52
第一题
  1. $ awk 'BEGIN{FS="\\]\\["}{print | "sort -t']' -k9"}' test
复制代码
第二题
  1. $ awk 'BEGIN{FS="\\]\\["}{a[$0]=$9}END{for(i in a) print i | "sort -t']' -k9"}' test
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2