none
select-string and eliminate the file name of searched file RRS feed

  • Question

  • Is there a way with the select-string command to exclude the file name of the file you are searching and still get the line items that match your results?  Similar to the DOS find command results.  I am trying to become completely independent of a DOS window and still have to find to reduce log files and make them easy to read.

    Thanks

    Chris


    Chris J.

    Tuesday, November 11, 2014 7:47 PM

Answers

  • Sure.  Select-String returns MatchInfo objects, and the string value of the matched line is in the Line property of the objects.

    Select-String -Pattern 'text to match' -Path 'filename.ext' |
     Select -ExpandProperty Line


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Tuesday, November 11, 2014 8:13 PM
    Moderator

All replies

  • That is how Select-String works.

    type *.txt | Select-String hello


    ¯\_(ツ)_/¯

    Tuesday, November 11, 2014 8:10 PM
  • Sure.  Select-String returns MatchInfo objects, and the string value of the matched line is in the Line property of the objects.

    Select-String -Pattern 'text to match' -Path 'filename.ext' |
     Select -ExpandProperty Line


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Tuesday, November 11, 2014 8:13 PM
    Moderator