Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first problem you may run into is that in order to match across multiple lines, you need to process the file's contents as a single string rather than by individual line. For example, if you use Get-Content to read the contents of the file then by default it will give you an array of strings - one element for each line. To match across lines you want the file in a single string (and hope the file isn't too huge). You can do this like so:</p> <pre><code>$fileContent = [io.file]::ReadAllText("C:\file.txt") </code></pre> <p>Or in PowerShell 3.0 you can use Get-Content with the <code>-Raw</code> parameter:</p> <pre><code>$fileContent = Get-Content c:\file.txt -Raw </code></pre> <p>Then you need to specify a regex option to match across line terminators i.e. </p> <ul> <li>SingleLine mode (<code>.</code> matches any char <em>including</em> line feed), as well as </li> <li>Multiline mode (<code>^</code> and <code>$</code> match embedded line terminators), e.g.</li> <li><code>(?smi)</code> - note the "i" is to ignore case </li> </ul> <p>e.g.:</p> <pre><code>C:\&gt; $fileContent | Select-String '(?smi)([0-9a-f]{2}(-|\s*$)){6}.*?!' -AllMatches | Foreach {$_.Matches} | Foreach {$_.Value} 00-01-23-45-67-89 use profile PROFILE use rf-domain DOMAIN hostname ACCESSPOINT area inside ! 00-01-23-45-67-89 use profile PROFILE use rf-domain DOMAIN hostname ACCESSPOINT area inside ! </code></pre> <p>Use the <code>Select-String</code> cmdlet to do the search because you can specify <code>-AllMatches</code> and it will output all matches whereas the <code>-match</code> operator stops after the first match. Makes sense because it is a Boolean operator that just needs to determine if there is <em>a</em> match.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload