Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Powershell Script - Copy content from a file begin with a keyword

$
0
0

Hi Guys,

I have a requirement of copying content from a text file and print the output where the copy should begin with matching keyword in a file. Attached here is the sample file.

I need a script in such a way that it should copy all the contents beginning after "Group: primary Servers:" and print only the ip address as output..

Following are my script, but it displays content from beginning. Please note: my input file will vary each time. its actually an output on sho dns command on proxy. I need only the primary and alternate dns servers print as otput.

Text
$ips3 = 'C:\Users\Nishad.Ummar\Documents\test2.txt' $ips33 ='C:\Users\Nishad.Ummar\Documents\test3.txt' Get-Content $ips3 | Select-String -Pattern "primary" -Context 17 | Set-Content $ips33 $IPRegex = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" $ipadd2 = Get-Content $ips33 |...

Viewing all articles
Browse latest Browse all 15370


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>