I am attempting to read one file, store it in a variable and replace text in file 2 with the data from file 1. However, my output does not seem accurate. Here is my source:
$orders = Get-Content -path F:\test2.txt -Raw
$files = Get-Content -path F:\unt.txt -Raw
foreach($file in $orders)
{
$files.replace("var",$_) | Set-Content -path .\test3.txt
}
When I use "$_", the 'var' is replaced, but there seems to be no data. I've also used $orders, but I can't seem to increment the data on the string. The file I'm attempting to edit is as shows My unt.txt file is as follows and all instances of 'var' would need to be replaced but iteratively from the array, so the first var would be replaced by $orders[0], the second by $orders[1], but I am having difficulty.:
autECLSession.autECLPS.SendKeys "var"
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[enter]"
autECLSession.autECLPS.SendKeys "var"
However, when the file runs it shows as:
autECLSession.autECLPS.SendKeys ""
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[enter]"
autECLSession.autECLPS.SendKeys ""
Furthermore, when I try to use the variable, $orders, I can't seem to figure out how to track the data being sent, an example of the output looks like it is just pasting the entire variable. I attempted to use Split, but I run into the same problem:
autECLSession.autECLPS.SendKeys'H00697581'
H00699775
M00690370
A00694622
D00690481
U00695159
H00699618
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[enter]"
autECLSession.autECLPS.SendKeys'H00697581'
H00699775
M00690370
A00694622
D00690481
U00695159
H00699618
Apologies for not including the text, but here are my files. I am attempting to take the input from test2 and replacing all instances of 'var' in my unt.txt, but currently it is repeating the first spot in the array, H00697581. My test2 file:
H00697581
H00699775
M00690370
A00694622
D00690481
U00695159
H00699618
The test.3.txt is just the output, but I expect it to look like so:
autECLSession.autECLPS.SendKeys'H00697581'
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[enter]"
autECLSession.autECLPS.SendKeys'H00699775'
autECLSession.autECLOIA.WaitForInputReady
autECLSession.autECLPS.SendKeys "[enter]"
autECLSession.autECLPS.SendKeys'M00690370'
etc...