我在这样的文件中有一个字符串:
47:2016-10-25 20:24:21 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
301:2016-10-26 08:01:01 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
我有一个输入字符串作为日期" 2016-10-25"另一个输入字符串为"处理标识请求。发送身份响应"。
我想找到不。字符串中存在的字符串。我试过这个:
total_attempt=$(grep -c "$i\|\[HSM \]Handle Identity Request. Send
Identity Response. timeout: 1550s" $file_name
我相信|在上面的语法中将无效。
注意:$ i是输入日期
输出应该是:
2016-10-25: = attempts = 2
但这不起作用。
Sed命令会有所帮助,但我不确定如何?
答案 0 :(得分:0)
#!/bin/bash
file_name=yourFile
i="2016-10-25"
total_attempt=$(grep -c "$i\|\[HSM \]Handle Identity Request. Send Identity Response. timeout: 1550s" $file_name)
echo $total_attempt
答案 1 :(得分:0)
要使|
生效,您需要启用扩展正则表达式,即也将-E
开关传递给grep。