← 返回 bytedance 的题目列表Write a Shell Script (On-site)
类型:online_judge
Coding: Write a Shell Script (On-site)
Write a bash script that reads log lines from stdin and prints aggregated statistics.
Input
Multiple lines, each in the format:
<TIMESTAMP> <LEVEL> <SERVICE> <MESSAGE>
LEVEL is one of: INFO/WARN/ERROR
Input ends at EOF
Output
Count ERROR lines per SERVICE, and output sorted by descending error count:
<SERVICE> <ERROR_COUNT>
If counts tie, sort by service name ascending.
Constraints
Up to 1e6 lines.
Only LEVEL=ERROR lines are counted.
Skip empty lines or malformed lines.
Example
Input:
2026-01-01T00:00:01Z INFO api started
2026-01-01T00:00:02Z ERROR api failed
2026-01-01T00:00:03Z ERROR db timeout
2026-01-01T00:00:04Z ERROR api failed2
Output:
api 2
db 1
Example
Input
2026-01-01T00:00:01Z INFO api started
2026-01-01T00:00:02Z ERROR api failed
2026-01-01T00:00:03Z ERROR db timeout
2026-01-01T00:00:04Z ERROR api failed2
Output
api 2
db 1