로그 파일:

로그 파일:

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

관련 정보