I have a below data in a text file.
author ; testname1 Revision ; 121 Date ; 10/5/2018 Path ; dev/test1 Message ; notes: testdata1 author ; testname2 Revision ; 1212 Date ; 10/6/2018 Path ; dev/test2 Message ; notes: testdata2 author ; testname3 Revision ; 1213 Date ; 10/5/2018 Path ; dev/test3 Message ; notes: testdata3 I want to read this and export to CSV which look like below.
author,Revision,Date,Path,Message testname1,121,10/5/2018,dev/test1,notes: testdata1 testname2,1212,10/6/2018,dev/test2,notes: testdata2 testname3,1213,10/5/2018,dev/test3,notes: testdata3 Any suggestions?
I have tried below code
$local:InputFilePath = "path of file" $local:OutFilePathCSV = "path of csv file" $local:CSVDelimiter = "," $local:OutDataList = New-Object -TypeName System.Collections.Arraylist $local:CurrentDataList = New-Object -TypeName System.Collections.Hashtable Select-String -Path $InputFilePath -Pattern "^[\s]" -NotMatch | ForEach-Object { $local:CurrentLine = ($_.Line).TrimEnd() $CurrentLine $OutDataList.Add($(New-Object -TypeName System.Management.Automation.PSObject -Property $CurrentDataList)) | Out-Null $CurrentDataList.Clear() if ($CurrentLine -match "^[\s]*([\w]*)[\s]+(.*)") { $CurrentDataList.Add($matches[1], $matches[2]) $matches[1] $matches[2] #break } } $OutDataList | Sort-Object -Property Serial | Select-Object -Property author, Revision, Date, Action, Path | Export-Csv -Path $OutFilePathCSV -Delimiter $CSVDelimiter -NoTypeInformation