Bird
0
0

You want to search for the word 'error' in all '.log' files in a folder and output only the matching text, not file names or line numbers. Which command achieves this?

hard📝 Application Q8 of 15
PowerShell - String Operations
You want to search for the word 'error' in all '.log' files in a folder and output only the matching text, not file names or line numbers. Which command achieves this?
ASelect-String -Pattern 'error' -Path '*.log' | ForEach-Object { $_.Matches.Value }
BSelect-String -Pattern 'error' -Path '*.log' -Raw
CSelect-String -Pattern 'error' -Path '*.log' -Quiet
DSelect-String -Pattern 'error' -Path '*.log' | Select-Object Line
Step-by-Step Solution
Solution:
  1. Step 1: Understand output requirements

    We want only matching text, no file names or line numbers.
  2. Step 2: Analyze each option

    Select-String -Pattern 'error' -Path '*.log' | ForEach-Object { $_.Matches.Value } extracts matched text using Matches.Value. Select-String -Pattern 'error' -Path '*.log' -Raw outputs raw file content, not matches. Select-String -Pattern 'error' -Path '*.log' -Quiet returns only True/False. Select-String -Pattern 'error' -Path '*.log' | Select-Object Line outputs full line, not just match.
  3. Final Answer:

    Select-String -Pattern 'error' -Path '*.log' | ForEach-Object { $_.Matches.Value } -> Option A
  4. Quick Check:

    Extract matches with Matches.Value [OK]
Quick Trick: Use Matches.Value to get only matched text [OK]
Common Mistakes:
  • Using -Raw to get matches
  • Expecting -Quiet to output text
  • Selecting full line instead of match

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes