Multiple counts in grep? -
so have big log file each line contains date. count number of lines containing each date.
i came awful solution, consisting of manually typing each of following commands:
grep -c "2014-01-01" big.log grep -c "2014-01-02" big.log grep -c "2014-01-03" big.log
i have written small python script, seems overkill. there quicker / more elegant solution?
you can maybe use of regex , uniq -c
count results.
see example:
$ cat 2014-01-03 aaa 2014-01-03 aaa 2014-01-02 aaa 2014-01-01 aaa 2014-01-04 aaa hello 2014-01-01 aaa
and let's 2014-01-0x
, being x
digit, , count them:
$ grep -o "2014-01-0[0-9]" | sort | uniq -c 2 2014-01-01 1 2014-01-02 2 2014-01-03 1 2014-01-04
note piping sort
needed make uniq -c
work properly. can see more info in answer what meaning of delimiter in cut , why in command sorting twice?.
Comments
Post a Comment