0

i try to get just 1.1.2.1 but it shows me other ip too

my test code is

$reader = @([System.IO.File]::ReadAllLines("c:\test2.log")) |select-string "1.1.2.1"

$reader = [System.IO.File]::ReadAllLines("c:\test2.log") |select-string "1.1.2.1"

$reader = get-content c:\test2.log |select-string "1.1.2.1"

and

  • test2.log

    10.1.101.1  test101
    
    10.1.102.1  test102
    
    121.132.252.1   test104
    
    100.101.122.1   test105
    
    1.1.1.1 test1
    
    1.1.2.1 test2
    
  • result

    10.1.102.1    test102
    
    100.101.122.1    test105
    
    1.1.2.1    test2
    

i don't know why it shows me test102,test105

please anyone tell me how to fix this

i tried this in Powershell v2,v3


sorry i forgot to explan a part of original code

{$pinghostname = Get-Content $HOSTS |Select-String -Pattern "$ip" | %{($_ -split "tt")[1]}

"1.1.2.1" should be a $ip

it means i can't use regexp

Angel Cha
  • 1
  • 2

1 Answers1

0
get-content test2.log | Select-String "1\.1\.2\.1"

works, as does

$ip="1\.1\.2\.1"
get-content test2.log | Select-String $ip
Phillip Ngan
  • 15,482
  • 8
  • 63
  • 79
  • {$pinghostname = Get-Content $HOSTS |Select-String -Pattern "$ip" | %{($_ -split "tt")[1]} "1.1.2.1" should be a $ip it means i can't use regexp – Angel Cha May 29 '18 at 07:33