이걸 awk 로 간단히 작성할수 있는지요?
글쓴이: hurryon / 작성시간: 목, 2003/11/20 - 2:20오전
입력 파일의 내용은 다음과 같습니다.
03:21:05 All Clients Now Started 03:21:07 Request 2113 03:21:07 Request 2143 03:21:07 Request 2173 03:21:08 Request 3185 03:21:09 Request 3265 03:21:09 Request 3285 03:21:09 Request 3285 03:21:09 Request 3305 03:21:09 Request 3305 03:21:09 Request 3305 03:21:09 Request 3365 03:21:09 Request 3365 03:21:09 Request 3385 03:21:09 Request 4206 03:21:11 Request 5378 03:21:11 Request 5608 03:21:11 Request 5959 03:21:12 Request 6810 03:21:12 Request 6810 03:21:12 Request 6810 03:21:12 Request 6820 03:21:12 Request 6820 03:21:12 Request 6840 03:21:12 Request 40 03:21:12 Request 40 03:21:12 Request 6840 03:21:12 Request 50 03:21:12 Request 30 03:21:12 Request 30 03:21:12 Request 20 03:21:12 Request 10 03:21:12 Request 6870 03:21:12 Request 30 03:21:12 Request 60 03:21:12 Request 50
시간 대 별루 Request 다음에 나오는 숫자을 더해서 합계과 평균을 출력하려고 합니다. 뭐 출력 양식이야 <시간> <합계> <평균> 이런식으로 말입니다. C 로 작성하긴 했는데...간단히 awk 같은 녀석으로 처리할수 있을텐데 하고 생각하기에...내공을 얻고자 이렇게 글을 올립니다.
:-)
Forums:
awk '/Request/ {s += $3 } END {print "SU
awk '/Request/ {s += $3 } END {print "SUM:", s}'
---
http://coolengineer.com
위 답변에 평균이 빠졌군요.awk '{s += $3 ; cnt +
위 답변에 평균이 빠졌군요.
awk '{s += $3 ; cnt += 1} END {print s, s/cnt}'
[code:1]awk 'BEGIN {prevtm = &quo
Life is tragedy when seen in close-up, but a comedy in long-shot.
냠냠...
으흠. 제가 설명이 부족했던 모양이군요...<시간> <합계> <평균> 과 같은 식이라고 했는데 <총합계> <총평균> 으로 이해을 하신듯...합니다.
시간이 초 단위로 되어 있는데 이것들에 대한 결과을...뽑아내는 것을 원하는것인데 말입니다.
가령 예을 들어...
과 같은 식으로 말이죠. 냠냠...이걸 못해서 간만에 C 코드로 1시간을 넘게 했기 때문에 혹시 다음번에도 이런 로그파일을 파싱해야 할 일이 생기면 awk 로 멋지게 작업하고 싶습니다. :-)
awk '/Request/ { if( t != $1 ) { if(cnt)
awk '/Request/ { if( t != $1 ) { if(cnt) print(t, s, s/cnt); t= $1; s=0; cnt=0}; s += $3; cnt += 1 } END {print t, s, s/cnt}'
---
http://coolengineer.com
pynoos 님 감사합니다...
awk의 강력함을 한 수 배워갑니다~~~
댓글 달기