grep for substrings present for each string in file - shell script -


i have strings in file this:

 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 

i have 1 input string date"2016-10-25" , input string "handle identity request. send identity response".

i want find no. of strings present in file. tried this:

  total_attempt=$(grep -c "$i\|\[hsm \]handle identity request. send    identity response. timeout: 1550s" $file_name 

i believe | in above syntax not work.

note: $i date input

the output should like:

 2016-10-25: = attempts = 2  

but not working.

sed commands help, not sure how?

could try this;

#!/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 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -