Bird
0
0

What will be the output of this command if 'data.txt' contains the line 'PowerShell rocks!':

medium📝 Command Output Q4 of 15
PowerShell - String Operations
What will be the output of this command if 'data.txt' contains the line 'PowerShell rocks!':
Select-String -Pattern 'rocks' -Path 'data.txt'
APowerShell rocks!
Bdata.txt:1:PowerShell rocks!
CNo output
DError: Pattern not found
Step-by-Step Solution
Solution:
  1. Step 1: Understand Select-String output format

    It shows filename, line number, and matching line.
  2. Step 2: Match pattern with file content

    'rocks' is found on line 1 in 'data.txt', so output includes filename, line number, and line.
  3. Final Answer:

    data.txt:1:PowerShell rocks! -> Option B
  4. Quick Check:

    Output format = filename:line:content [OK]
Quick Trick: Select-String shows filename, line number, and matching text [OK]
Common Mistakes:
  • Expecting only matched text without filename
  • Assuming no output if pattern found
  • Confusing error messages with no matches

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes