Bird
0
0

How can you search for the word 'Warning' in a file ignoring case sensitivity and output only the line numbers where it appears?

hard📝 Application Q9 of 15
PowerShell - String Operations
How can you search for the word 'Warning' in a file ignoring case sensitivity and output only the line numbers where it appears?
ASelect-String -Pattern 'Warning' -Path 'log.txt' -CaseSensitive | Select-Object LineNumber
BSelect-String -Pattern 'Warning' -Path 'log.txt' -IgnoreCase | Select-Object LineNumber
CSelect-String -Pattern 'Warning' -Path 'log.txt' | Select-Object LineNumber
DSelect-String -Pattern 'Warning' -Path 'log.txt' -CaseSensitive:$false | Select-Object LineNumber
Step-by-Step Solution
Solution:
  1. Step 1: Identify default behavior

    Select-String performs case-insensitive matching by default.
  2. Step 2: Select only line numbers

    Piping to Select-Object LineNumber outputs just the line numbers.
  3. Final Answer:

    Select-String -Pattern 'Warning' -Path 'log.txt' | Select-Object LineNumber -> Option C
  4. Quick Check:

    Default case-insensitive [OK]
Quick Trick: Select-String ignores case by default [OK]
Common Mistakes:
  • Using -CaseSensitive parameter (forces case-sensitive matching)
  • Using non-existent -IgnoreCase parameter
  • Selecting full lines instead of line numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes