Junior
How to extract only errors from a VoIP log file?
sobes.tech AI
Answer from AI
Command-line utilities can be used to filter log file contents.
For example, using grep:
# Filter lines containing the word "error" (case-insensitive)
grep -i "error" /path/to/voip/log/file.log
# Filter lines containing error patterns
grep -E "ERROR|CRITICAL|FATAL" /path/to/voip/log/file.log
Using awk:
# Filter lines where the second field (e.g., log level) equals "ERROR"
awk '{ if ($2 == "ERROR") print }' /path/to/voip/log/file.log
Using sed:
# Delete lines that do NOT contain the word "error"
sed -n '/error/Ip' /path/to/voip/log/file.log
The choice of utility depends on the VoIP log format and the required filtering precision. It is often useful to combine utilities, for example, using grep for initial filtering and awk for further processing or extracting specific fields.
For example, if log levels are at the beginning of each line:
# Filter lines starting with ERROR:
grep "^ERROR:" /path/to/voip/log/file.log
# Filter lines starting with ERROR:, CRITICAL:, or FATAL:
grep -E "^(ERROR|CRITICAL|FATAL):" /path/to/voip/log/file.log
If the log file is very large, zgrep can be used for compressed files (.gz).
zgrep -i "error" /path/to/voip/log/file.log.gz
For real-time error monitoring, tail combined with grep can be used:
# Monitor new log lines and display only those containing "error"
tail -f /path/to/voip/log/file.log | grep -i "error"