ログファイル:

ログファイル:

1) version.txt という名前のログ ファイルがあり、キーワード「took ? ms」を含むすべての単語をフィルター処理する必要があります。ms の前の数字 (「took ?? ms」) は、ログ エントリごとに異なります。

出力は次のようになります。

took 4 ms
took 3 ms
took 4 ms
took 5 ms

2) 100 を超える値をリストすることも可能です。つまり、100 を超える値をリストする必要があります。出力は次のようになります。

took 100 ms
took 110 ms
took 450 ms

ログファイル:

2020-03-11 06:19:29.857  INFO 29371 --- [  async-task-32] c.l.s.mapstore.InventoryPictureMapStore  : InventoryPictureMapStore.store() called **took 4 ms** key: I,748518,00000,00000,595 Value: InventoryPicture [, sourcingEnabled=false, itemType=1, onHand_1=100, buffer_22=-1] writeToCassandra: true

2020-03-11 06:19:29.857  INFO 29371 --- [  async-task-10] c.l.s.mapstore.InventoryPictureMapStore  : InventoryPictureMapStore.store() called **took 3 ms** key: I,26221,00000,00000,595 Value: InventoryPicture [, sourcingEnabled=false, itemType=1, onHand_1=-29, damaged_3=-1] writeToCassandra: true

2020-03-11 06:19:29.857  INFO 29371 --- [  async-task-13] c.l.s.mapstore.InventoryPictureMapStore  : InventoryPictureMapStore.store() called **took 4 ms** key: I,960808,00000,00000,595 Value: InventoryPicture [, sourcingEnabled=false, itemType=1, onHand_1=14] writeToCassandra: true

2020-03-11 06:19:29.857  INFO 29371 --- [  async-task-30] c.l.s.mapstore.InventoryPictureMapStore  : InventoryPictureMapStore.store() called **took 5 ms** key: I,771963,00000,00000,595 Value: InventoryPicture [, sourcingEnabled=false, itemType=1, onHand_1=64, buffer_22=-1] writeToCassandra: true


2020-03-11 06:19:29.857  INFO 29371 --- [  async-task-30] c.l.s.mapstore.InventoryPictureMapStore  : InventoryPictureMapStore.store() called **took 100 ms** key: I,771963,00000,00000,595 Value: InventoryPicture [, sourcingEnabled=false, itemType=1, onHand_1=64, buffer_22=-1] writeToCassandra: true

2020-03-11 06:19:29.857  INFO 29371 --- [  async-task-30] c.l.s.mapstore.InventoryPictureMapStore  : InventoryPictureMapStore.store() called **took 110 ms** key: I,771963,00000,00000,595 Value: InventoryPicture [, sourcingEnabled=false, itemType=1, onHand_1=64, buffer_22=-1] writeToCassandra: true

2020-03-11 06:19:29.857  INFO 29371 --- [  async-task-30] c.l.s.mapstore.InventoryPictureMapStore  : InventoryPictureMapStore.store() called **took 400 ms** key: I,771963,00000,00000,595 Value: InventoryPicture [, sourcingEnabled=false, itemType=1, onHand_1=64, buffer_22=-1] writeToCassandra: true

答え1

これを試すことができます:

grep -oP "took [[:digit:]]{3,} ms" file

出力:

took 100 ms
took 110 ms
took 400 ms

ありがとうございます。日付/時刻もリストすることは可能ですか? 出力は次のようになります:

2020-03-11 06:19:29.857 100 ミリ秒かかりました

2020-03-11 06:19:29.857 110 ミリ秒かかりました

すべてのレコードが同じ形式であると仮定すると、 、 を使用すると簡単にcutなりますsedgrep

cut -d' ' -f1,2,15-17 file | sed 's/*//g' | grep -P "took [[:digit:]]{3,} ms"

2020-03-11 06:19:29.857 took 100 ms
2020-03-11 06:19:29.857 took 110 ms
2020-03-11 06:19:29.857 took 400 ms

答え2

次の方法を使用してこれを実行できますawk:

awk -F '**' '{print $2}' input_file

時間と日付を追加するには、次のようなものを使用できます。

awk -F '**' '{split($1,a," ");print a[1]" " a[2]" " $2}' input_file

関連情報