powershell - Merging CSV files -



powershell - Merging CSV files -

i trying merge number of csv files big csv file. wrote powershell script create individual csv files each tag names. when added get-content @ end, error:

get-content : object @ specified path c:\htd2csv\output_files\*.csv not exist, or has been filtered -include or -exclude parameter. @ c:\htd2csv\extract.ps1:30 char:20 + $temp = get-content <<<< "$destinationpath\*.csv" #| set-content $destinationpath\merged.csv + categoryinfo : objectnotfound: (system.string[]:string[]) [get-content], exception + fullyqualifiederrorid : itemnotfound,microsoft.powershell.commands.getcontentcommand

but have csv files in output_files folder. entering get-content .\output_files\*.csv worked fine on command line, apparently not in script. code looks this:

$currentpath = [system.io.path]::getdirectoryname($myinvocation.mycommand.definition) $sourcepath = "c:\program files (x86)\proficy\proficy ifix\htrdata" $destinationpath = "$currentpath\output_files" @( "ppp_ve0963a", "ppp_ve0963b", "ppp_ve0964a", "ppp_ve0964b", "ppp_ve0967a", "ppp_ve0967b", "ppp_ze0963a", "ppp_ze0963b", "ppp_ze0964a", "ppp_ze0964b" ) | foreach-object { .\htd2csv.exe ` ppp:$_.f_cv ` /dur:00:23:59:00 ` /int:00:01:00 ` /sd:05/01/14 ` /st:00:00:00 ` /sp:$sourcepath ` /dp:$destinationpath\$_.csv ` /dtf:0 ` /dbg:0 } get-content "$destinationpath\*.csv" | set-content "$destinationpath\merged.csv"

don't utilize get-content/set-content merging csvs (assuming have csvs , not peculiarly named flat text files). utilize import-csv , export-csv:

get-childitem '*.csv' | % { import-csv $_.fullname | export-csv 'c:\path\to\merged.csv' -notype -append }

or (to avoid appending):

get-childitem '*.csv' | % { import-csv $_.fullname } | export-csv 'c:\path\to\merged.csv' -notype

powershell csv

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -