0

我试图得到公正1.1.2.1,但它也向我展示了ip其他

我的测试代码是

$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"

  • 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
    
  • 结果

    10.1.102.1    test102
    
    100.101.122.1    test105
    
    1.1.2.1    test2
    

我不知道为什么它显示给我test102,test105

请任何人告诉我如何解决这个问题

我试过这个Powershell v2,v3


对不起,我忘了解释原始代码的一部分

{$pinghostname = 获取内容 $HOSTS |Select-String -Pattern "$ip" | %{($_ -split " tt")[1]}

“1.1.2.1”应该是一个 $ip

这意味着我不能使用正则表达式

4

1 回答 1

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

工作,一样

$ip="1\.1\.2\.1"
get-content test2.log | Select-String $ip
于 2018-05-29T07:12:46.867 回答