linha de comando do powershell, diretório de criação, executado em D:\Data Set\
:
powershell 1..24^|%{md ('Angle'+$_)}
linha de comando do powershell, crie dados de teste:
powershell $i=0;$d='D:\Data Set\';$r=New-Object -T Random;1..24^|%{++$i;1..(random(11..17))^|%{$s='';1..20^|%{$rn=$r.Next();$s+=''+$rn+' '};$s.Trim();$s^|ac ($d+'Angle'+$i+'\output.txt')}}
- $ r = New-Object -T Aleatório - Criar objeto aleatório
- $ s.Trim () - exclui o espaço à esquerda e o lado direito da string
Execute o arquivo powershell:
powershell .\PasteD.ps1
PasteD.ps1, obtenha e escreva a coluna:
$d='D:\Data Set\' # work directory
$FileNum=24 # part path and filename
$Coln=9 # - 9th column
$LineMax=0 # init variable maximum line at text file
$dlm=' ' # delimiter
$i=0;1..$FileNum|%{++$i;$LineMax=[Math]::Max($LineMax,(gc ($d+'Angle'+$i+'\output.txt')|Measure).Count)}
# (gc <file name>|Measure).Count) - get line count at text file
# [Math]::Max - get Maximum line count at all file
# 1..$FileNum - cycle at Angle1, Angle2, etc up to Angle24 directory
# way init array:
#$arS =,''*$LineMax
#$arS =@('')*$LineMax
#$arS=[array]::CreateInstance('String', $LineMax)
#$arS=New-Object 'object[]' $LineMax
[string[]]$arS=@('')*$LineMax
For($i=0; $i -lt $FileNum-1; $i++) {
$f=gc ($d+'Angle'+($i+1)+'\output.txt') # get content file in Angle1..Angle23 dir
For($j=0; $j -lt $f.length; $j++) {
$arS[$j]=$arS[$j] + ($f[$j]-split' ')[$Coln-1] + $dlm # add value and delimiter
}
For($j=$f.length; $j -lt $LineMax; $j++) {
$arS[$j]=$arS[$j] + $dlm # add delimiter and empty value
}
}
$f=gc ($d+'Angle'+($FileNum)+'\output.txt') # get content file in Angle24 dir
For($j=0; $j -lt $f.length; $j++) {
$arS[$j]=$arS[$j] + ($f[$j]-split' ')[$Coln-1] # after last column not add delimiter
}
$arS|ac($d+'\total.txt') # save string array to result file