如何为一系列输入运行 grep 命令? [英] How do I run grep command for a range of inputs?

查看:44
本文介绍了如何为一系列输入运行 grep 命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以下 grep 命令来查找日志中每小时收到的请求数:

I need the following grep command to find how many requests per hour are received in logs:

grep 'login log' filelog.txt | grep -c '2017-08-30 ":00 to :23"'

这里是 00 到 23 小时,我需要作为参数传递.例如,对于日期 30,我需要查看每小时的计数.

Here the hour 00 till 23, I need to pass as a parameter. For instance, for date 30 I need to see each hour what was the count.

是否可以使用单个命令?目前我必须每小时手动执行一个命令.例如,

Is it possible using a single command? Currently I have to execute one command for each hour manually. For example,

$grep 'login log' filelog.txt | grep -c '2017-08-30 :00'
123
$grep 'login log' filelog.txt | grep -c '2017-08-30 :01'
456

这里是文件中的日志行,我想根据时间(第二列)每小时计算一次:

Here are log lines inside the file which I wanted to count hourly based on time (second column):

2017-08-30 20:19:47 INFO  com.java.JavaFile:123 - login log  abcduser

推荐答案

grep "yourstring" filelog.txt |
   grep -Eo "^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}" | sort | uniq -c

这篇关于如何为一系列输入运行 grep 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆