select-string NOT working

This topic contains 1 reply, has 2 voices, and was last updated by  Olaf Soyk 1 year ago.

  • Author
    Posts
  • #57061

    Kevin Sexton
    Participant

    I am trying to find the 1st occurrence of a string in each file. But it returns ALL the occurrences in each file. What am I doing wrong?
    Select-String -Path "c:\downloads\trash\*" -Pattern "aaa"

    C:\downloads\trash\1.txt:1:aaa
    C:\downloads\trash\1.txt:3:aaa
    C:\downloads\trash\3.txt:5:aaa
    C:\downloads\trash\3.txt:9:aaa

  • #57064

    Olaf Soyk
    Participant

    You're doing nothing wrong. That's what Select-String is made for. If you just want the first match:

    Select-String -Path "c:\downloads\trash\*" -Pattern "aaa" | Select-Object -First 1

You must be logged in to reply to this topic.