XK0-006 grep -E Practice Question
A security analyst wants to identify all lines in a log file that contain either 'ERROR' or 'WARNING' and also contain 'timeout'. Which three commands can be used to achieve this? (Select THREE).
⚠ Common exam trap
Candidates might think grep -E with alternation and chained patterns works like a logical AND, but forcing order with '.*' is not the same as checking both conditions independently.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
grep -E 'ERROR|WARNING' logfile | grep timeout
The correct commands are C, D, and E. Option C uses grep -E with alternation to first match lines containing 'ERROR' or 'WARNING', then pipes to another grep for 'timeout', ensuring both patterns appear in any order. Option D uses sed with alternation to print lines containing 'ERROR' or 'WARNING', then pipes to grep for 'timeout'. Option E uses awk with a condition requiring both patterns. Option B is incorrect because 'ERROR.*timeout|WARNING.*timeout' forces a specific order (e.g., 'timeout' must follow 'ERROR' or 'WARNING'), so it will miss lines where 'timeout' appears before the error/warning. Option A is wrong because -v inverts the match and the pattern lacks -E for alternation. Thus, only three options (C, D, E) correctly achieve the goal.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
grep -v 'ERROR|WARNING' logfile | grep timeout
Why it's wrong here
Incorrect. -v inverts the match, and 'ERROR|WARNING' is not treated as alternation without -E, so it matches the literal string 'ERROR|WARNING'.
- ✗
grep -E 'ERROR.*timeout|WARNING.*timeout' logfile
Why it's wrong here
Incorrect. 'ERROR.*timeout' and 'WARNING.*timeout' require 'timeout' to appear after the error/warning, missing lines with 'timeout' before.
- ✓
grep -E 'ERROR|WARNING' logfile | grep timeout
Why this is correct
Correct. First grep selects lines with 'ERROR' or 'WARNING' (using -E), then second grep ensures 'timeout' also appears.
- ✓
sed -n '/ERROR\|WARNING/p' logfile | grep timeout
Why this is correct
Correct. sed prints lines matching 'ERROR' or 'WARNING', then grep filters for 'timeout'.
- ✓
awk '/ERROR|WARNING/ && /timeout/' logfile
Why this is correct
Correct. awk condition '/ERROR|WARNING/ && /timeout/' prints lines containing both, order irrelevant.
Go deeper
Related to this question
About these practice questions
One of 979 original XK0-006 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This XK0-006 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the XK0-006 exam.