I initially thought this problem more complex than it actuially is but after digging around I still cant seem to find a solution that I can re-purpose. I'm trying to use wildcards but perhaps I'm going about this the wrong way
SQL*Plus: Release 11.2.0.1.0 Production on Wed Aug 13 14:20:22 2014
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
EXTERNAL ID
--------------------------------------------------------------------------------
'M1
---
12345678-1
M07
18765432-1
M14
19638527-1
M14
EXTERNAL ID
--------------------------------------------------------------------------------
'M1
---
17418529-1
M07
EXTERNAL ID M01
12345678-1 M07
18765432-1 M14
19638527-1 M14
17418529-1 M07
Any insight or help is appreciated
Here is something that I think will do what I want. It could probably be made more efficient and smaller but I went for easy to read and comprehend instead:
$res = @()
$content = get-content SomeFile.txt | ?{($_ -ne 'EXTERNAL ID') -AND (-NOT $_.StartsWith('"-')) -AND ($_ -ne "'M1") -AND (-NOT $_.Startswith('SQL*')) -AND ($_ -ne '')}
for($count = 0; $count -lt $content.Count; $count = $count + 2){
$id = $content[$count]
$m = $content[$count + 1]
$temp = New-Object PSCustomObject -Property @{'External ID' = $id;
'M01' = $m;
}
$res += $temp
}
$res | Export-CSV .\Som\Path\Name.csv -NoTypeInformation
Similar to EBGreen's answer, but simpler I think.
$Col2=$false
gc c:\temp\test.txt |Select -skip 6| ?{![string]::IsNullOrEmpty($_) -and $_ -notmatch "^(---|External|'M1)"} | %{
If($Col2){
[PSCustomObject][Ordered]@{
'External ID'=$Col1
"'M1"=$_}
$Col2=$false
}else{
$Col1=$_
$Col2=$true
}
} | Export-Csv C:\temp\New.csv -NoTypeInformation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.