Bird
0
0

Given a file 'data.txt' with the following lines:

medium📝 Command Output Q13 of 15
PowerShell - Regular Expressions
Given a file 'data.txt' with the following lines:
apple
banana
apricot
blueberry
avocado

What will the command Select-String -Pattern '^a' -Path 'data.txt' output?
ALines containing 'a' anywhere: apple, banana, apricot, avocado
BLines ending with 'a': banana
CLines starting with 'a': apple, apricot, avocado
DNo output because '^a' is invalid regex
Step-by-Step Solution
Solution:
  1. Step 1: Understand the regex '^a'

    The caret '^' means start of line, so '^a' matches lines starting with 'a'.
  2. Step 2: Apply regex to file lines

    Lines starting with 'a' are 'apple', 'apricot', and 'avocado'.
  3. Final Answer:

    Lines starting with 'a': apple, apricot, avocado -> Option C
  4. Quick Check:

    Regex '^a' matches line start with 'a' [OK]
Quick Trick: ^ means line start in regex, so matches lines starting with 'a' [OK]
Common Mistakes:
  • Thinking '^a' matches anywhere in line
  • Confusing '^' with end of line
  • Assuming no matches due to regex error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes