|
Re: More text processing. #create an empty array to hold the objects
$col = @()
# get the data in seven-line chuncks according to sequence on data sample
get-content data.txt -readCount 7 | % {
# create a new object
$obj = new-object psObject
# use Switch to create custom properties for the object
switch -regex ($_) {
# if $_ matches 'DSC' create the DSC property and assign its value
# by replacing al non-numeric characters
'^DSC' {
add-member noteProperty DSC $($_ -replace '\D*') -in $obj
}
# if $_ matches 'RLI' create the RLI property and assign its value
# by replacing al non-numeric characters
'^RLI' {
add-member noteProperty RLI $($_ -replace '\D*') -in $obj
}
# if $_ does not match 'DSC' or 'RLI' skip it
default {
continue
}
}
# add the object to the $col array
$col += $obj
}
$col
--
Kiron |