日志档案:

日志档案:

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,sed和 更容易grep

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

相关内容