다음 명령을 사용하여 로그 파일을 greping하고 있습니다.
grep "System has completed" my_log.log
그리고 다음과 같은 것을 얻으십시오
2019-12-07 17:03:09.527 System has completed 0 of 15778 files
2019-12-07 17:03:20.936 System has completed 4 of 15778 files
2019-12-07 17:03:32.381 System has completed 5 of 15778 files
2019-12-07 17:03:44.053 System has completed 5 of 15778 files
2019-12-07 17:03:55.753 System has completed 21 of 15778 files
2019-12-07 17:04:07.252 System has completed 22 of 15778 files
2019-12-07 17:04:18.728 System has completed 28 of 15778 files
2019-12-07 17:04:30.181 System has completed 28 of 15778 files
2019-12-07 17:04:41.627 System has completed 28 of 15778 files
이 결과를 추가로 처리하여 완료된 파일의 수가 중복되는 행을 잘라내어 출력이 다음과 같도록 하고 싶습니다.
2019-12-07 17:03:09.527 System has completed 0 of 15778 files
2019-12-07 17:03:20.936 System has completed 4 of 15778 files
2019-12-07 17:03:32.381 System has completed 5 of 15778 files
2019-12-07 17:03:55.753 System has completed 21 of 15778 files
2019-12-07 17:04:07.252 System has completed 22 of 15778 files
2019-12-07 17:04:18.728 System has completed 28 of 15778 files
여러 행이 동일한 숫자를 반복하는 경우 첫 번째 행만 유지됩니다. 타임스탬프로 인해 모든 고유 행을 단순히 필터링하는 것은 불가능합니다. 이를 수행하는 가장 좋은 방법은 무엇입니까?
답변1
숫자가 항상 같은 위치에 있다고 가정하면 다음을 사용할 수 있습니다 sort
.
grep "System has completed" my_log.log | sort -unk6,6
또는 uniq
:
grep "System has completed" my_log.log | uniq -f2