如何使用PowerShell检查文件中是否存在字符串? [英] How do I check a string exist in a file using powershell?

查看:128
本文介绍了如何使用PowerShell检查文件中是否存在字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have a 1st text file looks like this : 12AB34.US. The second text file is CD34EF. I want to find my 2nd text file exist or not in the 1st text file.

I tried to cut 3 characters last in the first text file (.US). Then I split to each 2 characters (because the 2nd text file consist of 2 characters). Then, I tried this code, and it always return "Not Found"





我尝试过:





What I have tried:

$String = Get-Content "C:\Users\te2.txt"
$Data = Get-Content "C:\Users\Fixed.txt"
$Split = $Data -split '(..)'

$Cut = $String.Substring(0,6)

$String_Split = $Cut -split '(..)'
$String_Split

$Check= $String_Split | %{$_ -match $Split}
if ($Check-contains $true) {
    Write-Host "0"
} else {
     Write-Host "1"
}

推荐答案

String = Get-ContentC:\ Users \ te2.txt
String = Get-Content "C:\Users\te2.txt"


Data = Get-ContentC:\ Users \Fixed.txt
Data = Get-Content "C:\Users\Fixed.txt"


Split =


这篇关于如何使用PowerShell检查文件中是否存在字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆