/build/static/layout/Breadcrumb_cap_w.png

I have 2 files that each have one line of text and I need to change the text in file 2 to match file 1

In each file the text says Port=3159(Different port number each time).

I need to change the port number in the second file to match the port number in the first file. Is there a way to do this in using a vbscript?


0 Comments   [ + ] Show comments

Answers (1)

Posted by: rileyz 4 years ago
Red Belt
0

Can do it in PowerShell, if that works for you?


Updated answer:
Got bored, here you go.


Comments:
  • $VerbosePreference = 'Continue'

    $FileA = Get-Content "C:\Media\File A.txt"
    $FileB = Get-Content "C:\Media\File B.txt"

    Write-Verbose 'Contents of File A'
    Write-Verbose $($FileA | Out-String)

    Write-Verbose 'Contents of File B'
    Write-Verbose $($FileB | Out-String)

    Write-Verbose 'Find and make change.'
    $FileA_PortNumber = $FileA -match '^Port=\d.*' #Regex Pattern, find match and assign to variable
    $FileB_PortNumber = $FileB -match '^Port=\d.*' #Regex Pattern, find match and assign to variable

    $FileB_IndexOfPort = $FileB.indexof("$FileB_PortNumber") #Assign index number from array, of where the port number is in the array
    $FileB.Item($FileB_IndexOfPort) = "$FileA_PortNumber" #Update file B, with port number from file A, based on the index number

    Write-Warning ' Updated Contents of File B'
    Write-Verbose $($FileB | Out-String)

    Write-Verbose 'Updating file'
    $FileB | Set-Content "C:\Media\File B.txt" - rileyz 4 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ