Click here to Skip to main content
15,888,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"
}
Posted
Updated 7-Mar-19 20:57pm
v2
Comments
Richard MacCutchan 8-Mar-19 4:03am    
Add some debug code to display the interim results through the script so you can see the actual data that it is looking at.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900