Powershell - Parsing a result text file to a .CSV file -


i'm new powershell , need guidance, please. trying read text file below , create custom .csv file allow easy database managing.

currently have tried using:

attempt #1

get-content d:\parsingproject\cdmv3\cdmv3.txt $sequentialread  = $array | select-string -pattern "sequential read :" $sequentialreadresults = $sequentialread -split "sequential read :"  $csvcontents = @() # create empty array csv file $row = new-object system.object # create object append array $row | add-member -membertype noteproperty -name "seuqential reads" -value $sequentialreadresults  $csvcontents += $row # append new data array $csvcontents | export-csv -path d:\parsingproject\cdmv3\mycsv.csv 

attempt # 2 (this 1 incomplete)

$input_path = 'd:\parsingproject\cdmv3\cdmv3.txt' $output_file = 'd:\parsingproject\cdmv3\cdmv3_scores.txt' $regex = ‘[a-z\s]+[a-z]+[:\s}+[\d]+.[0-9]+\s[a-za\/]{1,4}’ select-string -path $input_path -pattern $regex -allmatches | %{$_.matches} | %{$_.value} > $output_file 

are either option 1 or 2 going in right direction i'm trying do?

thanks in advanced, appreciated. =)

text file:

----------------------------------------------------------------------- crystaldiskmark 3.0.3 x64 (c) 2007-2013 hiyohiyo ----------------------------------------------------------------------- * mb/s = 1,000,000 byte/s [sata/300 = 300,000,000 byte/s]  sequential read :   135.091 mb/s  sequential write :   126.046 mb/s  random read 512kb :    44.569 mb/s  random write 512kb :   117.965 mb/s  random read 4kb (qd=1) :     0.468 mb/s [   114.4 iops]  random write 4kb (qd=1) :     8.412 mb/s [  2053.6 iops]  random read 4kb (qd=32) :     0.654 mb/s [   159.6 iops]  random write 4kb (qd=32) :    10.751 mb/s [  2624.7 iops]  test : 1000 mb [c: 7.3% (64.9/889.4 gb)] (x5)  date : 2015/12/09 22:06:02  os : windows 8.1  [6.3 build 9600] (x64) 

expected output in csv (without ------)

------column1-----------------------------column2----------column3   row1-subtest----------------------------mb/s-------------iops  row2-sequential read :----------------135.091 mb/s  row3 random read 4kb (qd=1) :--0.468 mb/s---114.4 iops 

ok, regex works fine here think. let's try now...

get-content d:\parsingproject\cdmv3\cdmv3.txt |where{$_ -match "^(.*?) : (.+? mb\/s)( \[.*)?$"}|foreach{     [pscustomobject]@{         'subtest'=$matches[1]         'mb/s'=$matches[2]         'iops'=if($($matches[3])){$matches[3].trim(' []')         }     } } | export-csv d:\parsingproject\cdmv3\mycsv.csv -notype 

that match regex defined here, createa custom object based on matches found, , convert array of objects csv file this:

subtest                  mb/s         iops        sequential read          135.091 mb/s             sequential write         126.046 mb/s             random read 512kb        44.569 mb/s              random write 512kb       117.965 mb/s             random read 4kb (qd=1)   0.468 mb/s   114.4 iops  random write 4kb (qd=1)  8.412 mb/s   2053.6 iops random read 4kb (qd=32)  0.654 mb/s   159.6 iops  random write 4kb (qd=32) 10.751 mb/s  2624.7 iops 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -