Bird
0
0

Given a file 'log.txt' with lines:

medium📝 Command Output Q4 of 15
PowerShell - Regular Expressions
Given a file 'log.txt' with lines:
1. Error: Disk full
2. Warning: Low memory
3. Error: File not found
What is the output of Select-String -Pattern '^Error' -Path 'log.txt'?
ALines 1 and 3 with their content
BOnly line 2
CAll lines containing 'Error' anywhere
DNo output because pattern is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Understand '^Error' matches lines starting with 'Error'

    Lines 1 and 3 start with 'Error', line 2 does not.
  2. Step 2: Select-String outputs matching lines with line numbers

    So lines 1 and 3 with their content are output.
  3. Final Answer:

    Lines 1 and 3 with their content -> Option A
  4. Quick Check:

    Regex '^Error' matches line start only [OK]
Quick Trick: Use ^ to match start of line, output includes line numbers [OK]
Common Mistakes:
  • Assuming it matches 'Error' anywhere in line
  • Expecting line 2 to match
  • Thinking no output due to pattern error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes