2013-02-26 5 views
-2

I'v par fichier avec des lignes à construire commeExpression régulière compter quelques caractères

yyyy-mm-dd hh-mm-ss * -start * 
yyyy-mm-dd hh-mm-ss * -end * 

Quelqu'un peut-il me aider à construire regexp compter le plus courant « -MM-ss » et les imprimer triés? par * Je veux dire une chaîne

+1

Qu'est-ce que as-tu déjà essayé? – VVS

Répondre

1
awk '{split($2,a,"-");b[a[2]"-"a[3]]++}END{for(i in b)print i,b[i]}' your_file 

testé:

> cat temp 
yyyy-mm-dd hh-11-55 * -start * 
yyyy-mm-dd hh-11-55 * -start * 
yyyy-mm-dd hh-12-22 * -end * 
> nawk '{split($2,a,"-");b[a[2]"-"a[3]]++}END{for(i in b)print i,b[i]}' temp 
12-22 1 
11-55 2 
> 

ci-dessous est la commande qui imprime tous hh-mm d'abord, puis tout mm-ss:

awk '{split($2,a,"-");b[a[2]"-"a[3]]++;c[a[1]"-"a[2]]++}END{for(i in c)print i,c[i];for(i in b)print i,b[i]}' your_file 
+0

par * je veux dire n'importe quelle chaîne de toute façon merci, je veux aussi le faire pour imprimer d'abord tout commence hh-mm, puis tout se termine hh-mm – whd

0
$ cat tmp 
yyyy-mm-dd hh-11-55 * -start * 
yyyy-mm-dd hh-11-55 * -start * 
yyyy-mm-dd hh-12-22 * -end * 

$ cut -c 15-19 tmp | sort | uniq -c 
     2 11-55 
     1 12-22 
Questions connexes