none
Use PowerShell Select-String to find 2 periods within files ".." RRS feed

  • Question

  • I use Get-ChildItem with select string to find various items I am searching for. Here is an example:

    gci | ? {$_.extension -eq ".txt"}  | select-string "An internal server error occurred" -list

    the above line will search through all txt files looking for the specific text "An internal server error occurred".

    When I try to search all text files for ..   the results are displaying all files

    I found this online:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string?view=powershell-5.1

    which mentions

    -Path

    Specifies the path to the files to search. Wildcards are permitted. The default location is the local directory.+

    Specify files in the directory, such as log1.txt, .doc, or *.. If you specify only a directory, the command fails.

    I don't think the .. in the article is what's blocking me. I think that is more of a *.     with a period to end the sentence.

    Does anyone know how I can use Select-String to find what I am looking for?

    Thanks a bunch

    Thursday, August 24, 2017 9:32 PM

Answers

  • You post is very confusing and hard to read.  If you were to have just posted what you just posted it wouldn't have been so hard to determine your actually question.  Clarity in technical forums is critical.

    ".." means match any string that has and two characters.

    "Select-String"  uses RegEx match patterns. To search for the "period" character you must escape it like this "\." or use "-SimpleMatch".

    Always check help first:

    help Select-String -Full

     


    \_(ツ)_/

    • Marked as answer by TimAA Tuesday, October 24, 2017 4:57 PM
    Thursday, September 7, 2017 10:41 PM

All replies

  • This is all you need:

    select-string -Path c:\temp\* -Include *.txt -Pattern 'An internal server error occurred' -list


    \_(ツ)_/


    • Edited by jrv Thursday, August 24, 2017 10:33 PM
    Thursday, August 24, 2017 10:31 PM
  • Your code is not looking for Two Consecutive Periods.

    This is a snip from my original post:

    When I try to search all text files for ..   the results are displaying all files

    I can see how the Two Periods don't look like what I am searching for, I thought quotation marks would make it confusing         ".."

    What I want to do, is search the files for any file, that has  "  ..  "   

    Two Consecutive Periods

    Thanks for your help.   


    TimA

    Thursday, September 7, 2017 9:16 PM
  • You post is very confusing and hard to read.  If you were to have just posted what you just posted it wouldn't have been so hard to determine your actually question.  Clarity in technical forums is critical.

    ".." means match any string that has and two characters.

    "Select-String"  uses RegEx match patterns. To search for the "period" character you must escape it like this "\." or use "-SimpleMatch".

    Always check help first:

    help Select-String -Full

     


    \_(ツ)_/

    • Marked as answer by TimAA Tuesday, October 24, 2017 4:57 PM
    Thursday, September 7, 2017 10:41 PM
  • Thanks JRV.

    Your suggestion worked for me. I was hoping when I originally wrote the scenario I was being very thorough. I couldn't find a way to highlight the ----> or *..  <---- in my original post.

    This is what I typed to get what I was looking for:

    gci | ? {$_.extension -eq ".txt"} | Select-String ".." -simplematchThanks Again JRV

    Tuesday, October 24, 2017 8:19 PM