로그 파일:

로그 파일:

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 100ms 걸렸네요

2020-03-11 06:19:29.857 110ms 걸렸네요

모든 레코드의 형식이 동일하다고 가정하면 을 사용하면 cutsed쉽습니다 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

관련 정보