First.txt
10.10.10.10
10.9.9.9
10.8.8.8
10.7.7.7
Second.txt
xx-xx-xx-xx-xx-xx
yy-yy-yy-yy-yy-yy
zz-zz-zz-zz-zz-zz
aa-aa-aa-aa-aa-aa
first text file is the ip address and second text file is the mac details for the ip address, i need output like below,this ip address are in foreach loop so each ipaddress will be checked for mac details and stores out put in second.txt
10.10.10.10 mac details are xx-xx-xx-xx-xx-xx
10.9.9.9 mac details are yy-yy-yy-yy-yy-yy
i have tried all ways but getting output like
10.10.10.10
10.9.9.9
10.8.8.8
10.7.7.7
mac details are
xx-xx-xx-xx-xx-xx
yy-yy-yy-yy-yy-yy
zz-zz-zz-zz-zz-zz
aa-aa-aa-aa-aa-aa
code i used is
get-content first.txt,second.txt | set-content joined.txt
This isn't very hard to do, joining these two files.
The key is to load both files as variables then use a
for
loop to step through both files, one at a time, and assemble the new output.This syntax
"$($first[$i]) mac details...
says make a new string, and then get the value of whats in the $first, in the row or position number $i.The output will look like this:
I made it extra verbose to teach the principles behind what I'm doing, for you and future readers. Learning these techiques of stepping through files one at a time, cleaning up or building new output files put you on a path to success in PowerShell :)