linux搜索模式并打印其计数

linux搜索模式并打印其计数,linux,shell,count,grep,command,Linux,Shell,Count,Grep,Command,在下面的文章中,我试图对geoIs的所有模式进行grep。我的问题是,如何列出geoIs的不同值以及它的计数 例: 预期结果: GeoIs:"Paramount" 1 GeoIs:"undefined" 2 GeoIs:"178" 2 命令 zcat file.gz | grep-p“geoIs”:“*?.undefined*?”| sort-u-T.| wc-l 编辑1: GEOIS位于以下字符串中 012-10-02 09:32:45{"e":{"ec":100001,"st":134

在下面的文章中,我试图对geoIs的所有模式进行grep。我的问题是,如何列出geoIs的不同值以及它的计数

例:

预期结果:

GeoIs:"Paramount" 1
GeoIs:"undefined" 2
GeoIs:"178" 2
命令

zcat file.gz | grep-p“geoIs”:“*?.undefined*?”| sort-u-T.| wc-l

编辑1:

GEOIS位于以下字符串中

  012-10-02 09:32:45{"e":{"ec":100001,"st":1349170352455,"bd":"Mozilla%2F5.0%20(Windows%20NT%206.1)%20AppleWebKit%2F537.4%20(KHTMf01f02008592~rt%2366.657~rv%2366.228~as%2317~st%231349170293955~cat%231349170352431~sp%23as~c%2334~pat%231349128562942","smplCookie":"undefined","geoIPAddress":"122.107.154.58","geoCountry":"australia","geoCity":"Vermont","geoRegion":"Victoria","geoPostalCode":"undefined","geoLatitude":"undefined","geoLongitude":"undefined","geoMetro":"0","geoArea":"0","geoIs"}}

要返回频率表,请使用

sort | uniq -c | sort -n
对于您提供的示例数据,我将使用

zcat file.gz | cut -f1 -d, | sort | uniq -c | sort -n

zcat file.gz | grep -o '"searchstring":"[^"]*"'| sort | uniq -c | sort -n

要返回频率表,请使用

sort | uniq -c | sort -n
对于您提供的示例数据,我将使用

zcat file.gz | cut -f1 -d, | sort | uniq -c | sort -n

zcat file.gz | grep -o '"searchstring":"[^"]*"'| sort | uniq -c | sort -n
awk替代方案:

awk -F, '{a[$1]++;}END{for(x in a)if(x)print x,a[x]}' file


kent$  echo 'GeoIsp:"Paramount","sumthing else"
GeoIsp:"undefined","sumthing else"
GeoIsp:"undefined","sumthing else"
GeoIsp:"178","sumthing else"
GeoIsp:"178","sumthing else"
'|awk -F, '{a[$1]++;}END{for(x in a)if(x)print x,a[x]}'
GeoIsp:"Paramount" 1
GeoIsp:"undefined" 2
GeoIsp:"178" 2
awk替代方案:

awk -F, '{a[$1]++;}END{for(x in a)if(x)print x,a[x]}' file


kent$  echo 'GeoIsp:"Paramount","sumthing else"
GeoIsp:"undefined","sumthing else"
GeoIsp:"undefined","sumthing else"
GeoIsp:"178","sumthing else"
GeoIsp:"178","sumthing else"
'|awk -F, '{a[$1]++;}END{for(x in a)if(x)print x,a[x]}'
GeoIsp:"Paramount" 1
GeoIsp:"undefined" 2
GeoIsp:"178" 2

但很抱歉,它并不总是第一个字段。它是分散的..将编辑问题中的输入。请看一看,有10000行,如EDIT1中所述,具有不同的值,请使用
grep-o的“geoIsp”:“[^”]*“'
而不是
cut
部分。k m测试它会让你知道,但很抱歉,它并不总是第一个字段。它是分散的..将编辑问题中的输入。请看一下,有10000行,如EDIT1中所述,具有不同的值,请使用
grep-o''geoIsp:“[^”]*“
而不是
cut
part.km测试它会让你知道