title: Copy last column values
body: <p>I have a text file (dynamically generated by another script) as shown below:</p>
  
  <pre><code>host1       A      Answer     myip1
  host6557    A      Answer     myip2
  host12      A      Question   myip3
  host253     A      Answer     myip4
  </code></pre>
  
  <p>What I want: I need to copy "myip" columns from this file. As you can see the space between "host" and "A" is not fixed. For ex, between host1 and A has 7 spaces, but between host6557 and A has just 4 spaces. I need to just copy the last column which all will start with some values, say "10." or "192."</p>
  
  <p>How can this be achieved in PowerShell?</p>
  
  <p><strong>Update</strong></p>
  
  <ol>
  <li><p>I want this data to be pasted in another file in place of 1st column where the contents will be as shown below: Which means I need to replace values of ip1,2,3 with these copied values.</p>
  
  <p><img src="https://i.stack.imgur.com/SUVUu.png" alt="enter image description here"></p></li>
  <li><p>If it's done, suppose let's say I have 4th value like above (without credentials) I again need to copy the username, password from 3rd value and paste it there near to 4th value. Final expected figure:</p>
  
  <p><img src="https://i.stack.imgur.com/tGRHz.png" alt="enter image description here"></p></li>
  </ol>
  
  <p><strong>Update</strong></p>
  
  <pre class="lang-psh prettyprint-override"><code>$hip = Get-Content "C:\timezone\host - Copy.txt"
  foreach ($ips in $hip) {
    $ip = $ips -split ','
    $sip = $ip[0]
  
    if ($iplist -match $sip) {
      Write-Host "Nothing to do"
    } else {
      Add-Content $hip "`n$iplist',username,password'"
    }
  }
  </code></pre>
  
  <p>No error, but I cant find it checks the last if loop, because for all values it says "nothing to do".</p>