2016-11-10 4 views
1

私はこのようなファイル内の文字列を持っている:はgrep - シェルスクリプト

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 

私は1つの入力日付として文字列「2016年10月25日」と、別の入力文字列を持っています「身元識別要求を処理する。身元識別応答を送信する」として。

いいえ。ファイル内に存在する文字列の数。私はこれを試しました:

total_attempt=$(grep -c "$i\|\[HSM \]Handle Identity Request. Send 
    Identity Response. timeout: 1550s" $file_name 

私は信じて|上記の構文では動作しません。

注:

2016-10-25: = attempts = 2 

しかし、これは動作しません:$ iの入力

として出力するようにする必要があり日付です。

Sedコマンドが役に立ちますが、わかりません。

答えて

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 
0

、あなたはすなわちものgrepに-Eスイッチを通過し、拡張正規表現をオンにする必要があります。