Need to reformat a text file pattern into a different patterned output

I have a large text file that consists of the top 11 lines of a bunch of dns zone files.  I need to parse this file and create a new file that generates a single line for every iteration of the pattern.  Essentially the pattern consists of 11 lines, followed by a domain line and then repeats.  For example, the pattern looks like the following:

; *** This file is automatically generated by Plesk ***
$TTL	86400

@	IN	SOA	dauth5.domain.com. contact.domain2.com. (
			2018020603	; Serial
			10800	; Refresh
			3600	; Retry
			604800	; Expire
			10800 )	; Minimum

---------------domain2.com

Open in new window


This pattern repeats over and over for every domain name contained on our server.  What I would like is to parse the file for each of these 11 lines and return the following:

domain2.      SOA    dauth5.domain.com.  2018020603 10800 3600 604800 10800

The "domain2" above comes from line 11 each time.  Can anyone write a script or perhaps a quick way in Notepad++ to get the data formatted the way I want?  Thanks!
Chad KillionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
"Large text file" and "parse" seem to call for PowerShell.
Do you need the output just space separated, or as fixed column width (and if so, which width for which column?)
How exactly is the domain name generated? Just by cutting of .com, or the element after the last "."?
$inFile = 'C:\Temp\dns.txt'
$outFile = 'C:\Temp\dns_out.txt'
Get-Content -Path $inFile | ForEach-Object {
	Switch -Regex ($_) {
		'@\s+IN\s+\SOA\s+(?<SOA>\S+)' {$props = @{SOA = $Matches['SOA']}}
		'^\s+(?<Serial>\d+)\s*;\s*Serial' {$props['Serial'] = $Matches['Serial']}
		'^\s+(?<Refresh>\d+)\s*;\s*Refresh' {$props['Refresh'] = $Matches['Refresh']}
		'^\s+(?<Retry>\d+)\s*;\s*Retry' {$props['Retry'] = $Matches['Retry']}
		'^\s+(?<Expire>\d+)\s*;\s*Expire' {$props['Expire'] = $Matches['Expire']}
		'^\s+(?<Minimum>\d+)\s*\)\s*;\s*Minimum' {$props['Minimum'] = $Matches['Minimum']}
		'^-+(?<Domain>[^-]\S+)' {
			$props['Domain'] = $Matches['Domain']
			$outObject = New-Object -TypeName PSCustomObject -ArgumentList $props
			$outString = '{0} {1} {2} {3} {4} {5} {6} {7}' -f `
				$($outObject.Domain -replace 'com$'),
				'SOA',
				$outObject.SOA,
				$outObject.Serial,
				$outObject.Refresh,
				$outObject.Retry,
				$outObject.Expire,
				$outObject.Minimum
			$outString | Write-Host
			$outString
		}
	}
} | Set-Content -Path $outFile

Open in new window

Chad KillionAuthor Commented:
Sorry, I messed up a bit...that line should be the whole domain.com followed by a "."  This part should be pulled form the line 11 and always follows 15 "-" marks.  Space delimited is just fine as well.
oBdACommented:
Easy enough to fix, but first another question: does the domain in this line already have a "." at the end (that maybe got edited away), or does the "." need to be explicitly added?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Chad KillionAuthor Commented:
no, the . needs to be added to the end of the domain from line 11 each time.
oBdACommented:
Try this then:
$inFile = 'C:\Temp\dns.txt'
$outFile = 'C:\Temp\dns_out.txt'
Get-Content -Path $inFile | ForEach-Object {
	Switch -Regex ($_) {
		'@\s+IN\s+\SOA\s+(?<SOA>\S+)' {$props = @{SOA = $Matches['SOA']}}
		'^\s+(?<Serial>\d+)\s*;\s*Serial' {$props['Serial'] = $Matches['Serial']}
		'^\s+(?<Refresh>\d+)\s*;\s*Refresh' {$props['Refresh'] = $Matches['Refresh']}
		'^\s+(?<Retry>\d+)\s*;\s*Retry' {$props['Retry'] = $Matches['Retry']}
		'^\s+(?<Expire>\d+)\s*;\s*Expire' {$props['Expire'] = $Matches['Expire']}
		'^\s+(?<Minimum>\d+)\s*\)\s*;\s*Minimum' {$props['Minimum'] = $Matches['Minimum']}
		'^-+(?<Domain>[^-]\S+)' {
			$props['Domain'] = $Matches['Domain'] + '.'
			$outObject = New-Object -TypeName PSCustomObject -ArgumentList $props
			$outString = '{0} {1} {2} {3} {4} {5} {6} {7}' -f `
				$outObject.Domain,
				'SOA',
				$outObject.SOA,
				$outObject.Serial,
				$outObject.Refresh,
				$outObject.Retry,
				$outObject.Expire,
				$outObject.Minimum
			$outString | Write-Host
			$outString
		}
	}
} | Set-Content -Path $outFile

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chad KillionAuthor Commented:
Awesome!  Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.